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

pull records from a file based on a condition 1

Status
Not open for further replies.

mwesticle

Programmer
Nov 19, 2003
51
US
Hi... What's the best way to pull a record from a file if certain bytes match a string? For example, I have a fixed-width file that has a state code in the 200-201 byte of each record. I want to pull all records where state code = 'CA' 'NY' 'NJ' or 'FL', and put them into a new file. How do I go about this? Thanks!
 
The awk way:
Code:
awk 'BEGIN{a["CA"]=a["NY"]=a["NJ"]=a["FL"]}
{if(substr($0,200,2) in a) print}
' /path/to/input >output

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

Part and Inventory Search

Sponsor

Back
Top