1829638 Members
1609 Online
109992 Solutions
New Discussion

Re: awk statement

 
Sandeepk_1
Advisor

awk statement

can anyone validate this syntax and let know whether the output will be a desired one?
cat $filename | grep $UNO| awk -v reg=$region -v cir=$circle -v uno=$UNO '$18 > 90 && $3==uno {print reg"\t"cir" \t "$3" \t " $4"-"$5"-"$6" \t "$18 "\t"}'
7 REPLIES 7
Court Campbell
Honored Contributor

Re: awk statement

This makes no sense. We should not be the ones determining the desired output. Plus we do not know what is in the file that is being cat'ed, nor what the value of $UNO is, etc. How could we possibly answer this?
"The difference between me and you? I will read the man page." and "Respect the hat." and "You could just do a search on ITRC, you don't need to start a thread on a topic that's been answered 100 times already." Oh, and "What. no points???"
Stuart Browne
Honored Contributor

Re: awk statement

in any case, learn how to use a printf() statement.
One long-haired git at your service...
Sandeepk_1
Advisor

Re: awk statement

Thanks Court for an interesting reply!!! I would prefer if you would once again read my question carefully.
Thanks Stuart for the generous reply, I will definitely check out and learn.
Hein van den Heuvel
Honored Contributor

Re: awk statement


Sandeep,

Please re-read your own question carefully and now judge how anyone can possibly answer it?!

How can anyone know what 'desired' output is without specifying some details on both input and output format.

The suggested command might do something useful is the file pointed to by $filename is a file with white-space seperated columns where some lines contain $UNO in some 3rd columns. Some of those lines would need to have 18 or more columns and the value in column 18 should be larger than 90 for more that 1 of those.

But here is some free advide anyway!
Get rid of the 'cat' and the 'grep'!
Just let awk do the work!

awk -v... '$3==uno $18>90 {...}' $filename

Finally... have you simply tried it?
Just make a mock-up file with some valid lines and some bad lines.

Kindest regards,
Hein van den Heuvel.

Hein van den Heuvel
Honored Contributor

Re: awk statement

Oh, btw, you seem to want to make a Tab-Seperated-Values output file (easy for Excel).
The easiest way to do that in awk is to set the Output Field Seperator (OFS) to tab.

awk -v... 'BEGIN {OFS="\t"} $3==uno... {print reg,cir,$3,...}'

Hein.

Sandeepk_1
Advisor

Re: awk statement

Thanks alot everyone for your support. got the exact syntax done.
Sandeepk_1
Advisor

Re: awk statement

thanks once again