| | |
awk "for loop" and variables
![]() |
•
•
Join Date: Jul 2005
Posts: 2
Reputation:
Solved Threads: 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?
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?
•
•
Join Date: Oct 2007
Posts: 399
Reputation:
Solved Threads: 47
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
Perhaps something as simple as
var=`head -1 tex 2>&1|awk '{print $1}'`
woud do it ?
, Best wishes,
Mike
Linux and Unix Tips, Tricks and Individual Advice - The Linux and Unix Menagerie!
------------------------------------------------------------------------
The greatest viral marketing idea of all time, get your copy of this Free Report now!
------------------------------------------------------------------------
The greatest viral marketing idea of all time, get your copy of this Free Report now!
•
•
Join Date: Apr 2006
Posts: 148
Reputation:
Solved Threads: 40
Shell Scripting Syntax (Toggle Plain Text)
awk 'NR==1{ print "var="$1}' file
![]() |
Similar Threads
- Any keyword to break or continue a LOOP like as in C "break","continue" keawords?? (PHP)
- This ought to be simple - extra spaces (PHP)
- Keyboard input or "stuck in a loop" (C++)
- error mgs when trying to compute "for loop" (C++)
Other Threads in the Shell Scripting Forum
- Previous Thread: Help needed in this script
- Next Thread: Please help me write this simple script
| Thread Tools | Search this Thread |





