|
Arios26 Newbie
Joined: 04 Jul 2008 Posts: 4
|
Posted: Fri Jul 04, 2008 7:32 pm
Adding to a variable from a txt file |
Okay so I'm trying to add line 1 from a txt file to a variable. Then after my script does what it does, it goes to line 2 of the same txt file and adds that to a variable. How would I go about doing this?
|
|
|
|
MattLofton GURU
Joined: 23 Dec 2000 Posts: 4834 Location: USA
|
Posted: Sat Jul 05, 2008 5:31 am |
to read in the data from your file into the variable, check out the %read() function. You can choose between #FORALL, #LOOP, and #WHILE/#UNTIL for your looping.
|
|
_________________ EDIT: I didn't like my old signature |
|
|
|
Arios26 Newbie
Joined: 04 Jul 2008 Posts: 4
|
Posted: Sat Jul 05, 2008 11:56 am |
Yeah I've read it and still not sure exactly how to get it working. I've tried it, but don't have much luck. Iwould do something like this?
#file 1 something.txt
#var whatever %read(1,1)
But not exactly sure ... it says something about 0 doing the sequential line ... that sounds like what I'd want.. |
|
|
|
ralgith Sorcerer
Joined: 13 Jan 2006 Posts: 715
|
Posted: Sat Jul 05, 2008 3:53 pm |
You're going to need to loop it like he said.
But you'd do something like:
#FILE 1 something.txt
#LOOP %filesize(1) {#var whatever %read(1, %i)}
Obviously this is contrived. And just keeps resetting the whatever to each line of the file until file ends.
But I'm not sure where your #var assignment is in relation to the rest of the script. If it is all in an alias like this:
#ALIAS dork {
#var whatever blah
command1
command2
command3
}
Change it to this:
#ALIAS dork {
#LOOP %filesize(1)
#VAR whatever %read(1,%i)
command1
command2
command3
}
} |
|
_________________ CrossOver: Windows Compatibility on Mac and Linux CMUD Advocate |
|
|
|
ralgith Sorcerer
Joined: 13 Jan 2006 Posts: 715
|
Posted: Sat Jul 05, 2008 3:55 pm |
Or you could use 0, I never noticed that when using %read before. Course I didn't use it much either :)
|
|
_________________ CrossOver: Windows Compatibility on Mac and Linux CMUD Advocate |
|
|
|
Arios26 Newbie
Joined: 04 Jul 2008 Posts: 4
|
Posted: Sat Jul 05, 2008 4:35 pm |
Actually what I'm trying to do is make it pull it to a variable, intiate an alias, than pull the next line to that same variable replacing whats in it, initiate alias, etc til the file is empty.
So like:
pull to variable
do alias
pull next line to variable
do alias
pull next line to variable
do alias
etc etc etc. |
|
|
|
ralgith Sorcerer
Joined: 13 Jan 2006 Posts: 715
|
Posted: Sun Jul 06, 2008 5:07 pm |
So your way to initiate this could be:
#ALIAS dork {
#LOOP %filesize(1)
#VAR whatever %read(1,%i)
doalias
}
} |
|
_________________ CrossOver: Windows Compatibility on Mac and Linux CMUD Advocate |
|
|
|
|
|