Reputation: 15
Hello I am a bit new with coding so sorry if this does not make sense. I need help with a script I am trying to work on for a file. The file is comma delimited and would like to filter it to only show specific character and also keep it's header. I am trying to filter the file by collateral codes which is in field 10 and I have over 2000 records on this file.
Example:
Name, Address, Phone, Zip, Coll Code,
Susan Mary, abc, 12345678, 12345, T, etc..
Jon Doe, abc, 12345678, 12345, Y, etc..
Carry Mclaughlin, abc, 12345678, 12345, T, etc..
Larry Burk, abc, 12345678, 12345, M, etc..
Wanted Output:
Name, Address, Phone, Zip, Coll Code, etc..
Susan Mary, abc, 12345678, 12345, T, etc..
Carry Mclaughlin, abc, 12345678, 12345, T, etc..
here's the sample I am currently using (code is in field 10).
awk -F, '{if ($10 == "T") print $0}' originalfile > newfile
Only problem I am having right now is keepign the HEADER on this file.
-Thank you
Upvotes: 0
Views: 67
Reputation: 203209
It's hard to tell from your question but it sounds like this might be what you want:
awk -F, 'NR==1 || $10=="T"' file
Upvotes: 1
Reputation: 15
okay so took me an hour to finally figure this one out. Here is the command i used
awk -F, 'NR==1; NR > 1{if ($10 == "T") print $0}' originalfile > newfile
Upvotes: 0