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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Awk Script Problem

Status
Not open for further replies.

nogs

Technical User
Aug 3, 2001
89
GB
Im running this ;
cat FILE|awk -e '{ FS = "," ; if ($4 == "A") print $0 ; }' > afile

on this file;
2,01,01,A,60
2,01,02,A,53
2,01,03,A,46
2,01,04,A,39
2,01,05,A,32
2,01,06,A,25
2,01,07,A,18
2,01,08,A,11
2,01,09,A,04
2,01,10,A,76
2,01,11,A,69
2,01,12,A,62
2,01,13,B,55
2,01,14,A,48
2,01,15,A,41
2,01,16,A,34
2,01,17,A,27
2,01,18,A,20
2,01,19,B,13
2,01,20,A,06

For some reason the 1st record "2,01,01,A,60" is being missed and being picked up by other line to pick up all where $4 != "A"
Any ideas!!!!!

 
Hi, nogs!

If I use this awk examples, everything is OK;

Code:
awk -F, '$4 == "A"' file.txt

or

Code:
awk -F, '{ if ($4 == "A") print $0 }' file.txt

or

Code:
awk 'BEGIN { FS = "," }  { if ($4 == "A") print $0 }' file.txt

Authors of awk say that variable FS may be changed at any time to any single character, but I think that, in this case, you must specify FS in command line or in BEGIN statement.

Bye!

KP.
 
Hi Krunek
awk 'BEGIN { FS = "," } { if ($4 == "A") print $0 }' file.txt
Worked and got me out of a mess quick

Thanks
NOGS
 

BTW, NOGS,

if only field $4 has uppercase letters, you can use this awk or grep solutions:

Code:
awk '/A/' inputfile

or

Code:
grep A inputfile

Bye!

KP.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top