0

hi, i have a series of files like this one:

              D22 L58 two
              O12 L58 two
              Z5 L58 two
              Z19 L58 two

and i want to make the first column into a variable ($var) that will be used in the rest of the shell script
This is my awk script so far :

awk '{
   for (i = 1; i <= 1; i++)
   print "var="$i
   }' L58vector.txt > test.txt

but instead of producing a file (test.txt) containing just one ' var=D22'
i get:

         var=D22
         var=O12
         var=Z5
         var=Z19 

which renders the variable useless.

i then want to match this variable to the same number in another file which contains latitude and longitude data and print them to an output file before starting again with the next variable (var=O12)

can anyone help?

Edited by mike_2000_17: Fixed formatting

4
Contributors
3
Replies
6
Views
12 Years
Discussion Span
Last Post by ghostdog74
0

awk runs it's script once per line of input in the file. it automatically advances to the next record and feeds the input to your script. $1 is the first field of a record, and you print it once per record

0

This is true of sed, also.

Perhaps something as simple as

var=`head -1 tex 2>&1|awk '{print $1}'`

woud do it ?

, Best wishes,

Mike

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.