Richard Marza writes:
> FILE=`cat filename.txt`
> TICK=`cat filename.txt | wc -l'
> TOCK="0"
>
> while [ $TICK != $TOCK ] ; do
> let $TOCK=$TOCK+1
Or, simpler, as we are using bash: (( TOCK++ ))
> 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...)
>
> done
>
> exit 0
What should Var1 contain - "Dbase1" or the content of the file "Dbase1"?
What should Var2 contain - "5.0" or the content of the file "5.0"?
Because you are using cat in the assignment.
If you just need the values in a variable, do it like this:
file=filename.txt
Var1=( $( cat "$file" | awk '{ print $1 }' ) ) # creates an array variable
Var2=( $( cat "$file" | awk '{ print $2 }' ) )
The $() notation does the same as backticks, but is more readable. Using
foo=( ... ) will create foo as an array. I assume there is no whitespace in
your data, that is Var1 will never contain something like "Dbase 1".
${#va...@]} will contain the number of elements (your $TICK). To access the
5th element (for example), use ${Var1[4]}.
Oh, an please don't hijack threads by replying to an existing one, but start
a new one. This one appears inside the "Cloning movie DVDs" thread.
And feel free to ask more questions, maybe I got it all wrong.
Wonko