I am new to scripting and awk but have an 'easy' problem that I can't
solve.
How can I get a value from awk into a variable that I am using in a C
shell script?
e.g. I use awk thus:
awk 'NR==1 {print $1}'<inputfile #prints 1st field of 1st line of
file 'inputfile'
I want to store the output of this into a variable which I use later in
my C script. I have tried piping it but can't get it right. I have
also tried set variable = "awk...." but this doesn't work.
Although I can set the variable within the awk script, I can't get it
out into my C script. Ideas?
In addition to this, after having performed a number of operations, I
want to repeat the entire program, but this time setting NR=2 and so
on. I can't seem to set NR from outside of the awk script. What am I
doing wrong?
Lastly, the file I have doesn't have constant fields for each line,
mainly because there is some text in each line with spaces. As such,
awk gives a different field number for each line. Since I am trying to
make the script compatible for both linux and solaris systems, I can't
use the FIELDWIDTHS setting. Is there any way that I can set constant
field widths so that the parts containing text and spaces is treated as
one field?
Hope someone can help
TIA.
Jase