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

Select Records (awk, nawk, sed???) 1

Status
Not open for further replies.

mwesticle

Programmer
Nov 19, 2003
51
US
I need to select certain records from a file. The records are pipe-delimited, and therefore variable-length. The last two fields on the record are the onew I am concerned with. I want to pull records where the 2nd-to-last field = 'Y', and the last field = 'N'. For example, out of these four records:

123123|123123|123123|123213|Y|Y
23|123123|123123|123|Y|N
787878|8787|787878|87878|N|N
565656|5656|5656|565|N|Y

only this record would be pulled:

23|123123|123123|123|Y|N

I want to just re-direct my output to a file. Anyone know a quick and easy way to do this?
 
Code:
nawk -F'|' '$(NF-1) == "Y" && $NF == "N"' myInput.txt > myOuput.txt

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
Another way, with grep:
grep '|Y|N$' myInput.txt > myOuput.txt

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top