On Tuesday 11 August 2009 09:07:31 Richard Marza wrote:

> I'm trying to run a command in a loop. I have a counter device set...the
> number that the counter generates is supposed to go inside the command in
> the loop after every successive iteration of the loop. This is all really
> to get a general idea I've attached a snippet below.
>
> FILE=`cat filename.txt`
> TICK=`cat filename.txt | wc -l'
> TOCK="0"
>
> while [ $TICK != $TOCK ] ; do
>             let $TOCK=$TOCK+1
>             Var1= `cat FirstWordOfFirstColumnOfFirstLine` (This I actually
> achieved with sed and awk)
>             Var2=`cat FirstFloatOfFirstLine`   (The problem lies here; it's
> my inability to come up with a way of implementing a variable that changes
> along with the counter.  so that the second time this is run it doesn't do
> the first line but moved to the second line and the third line and so
> on...)

I'm not sure I understand what you want, but you can probably reimplement the 
whole thing in awk or sed only much more efficiently. To get more help on 
that, post a more complete description of the problem and the result you want 
to achieve. 
If you really want to keep the current logic, you can save the nth line of the 
file at iteration n and process it how many times you want:

# line number is in N

nthline=`sed -n "$N{p;q;}" file.txt`
var1=`echo "$nthline" | .....`
var2=`echo "$nthline" | .....`


Reply via email to