Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sorry,my english is poor. I descri

Status
Not open for further replies.

piggy213

Programmer
Sep 27, 2002
19
0
0
TW
Sorry,my english is poor.
I describe my question clearly as soon as possible.

Does anybody know how to use nawk in C shell to search two fields by two variable and print it?

eg.
If I set two variable $m and $d from month and date and they are field two and field three in file.

nawk '$2==/$m/ && $3==/$d {print}' infile

Is the above program right?
If it is wrong ,please help me to correct it.
Thanks a lot.
 
Hi:

This is a solution to your problem:

#!/bin/csh
set m=2
set d=3
nawk -v mm=$m -v dd=$d ' { if($2==mm && $3==dd) print } ' infile

There's a faq over in the awk forum:

faq271-1281

that describes 3 methods of handling shell variables in awk.

Regards,

Ed
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top