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!

sort a file based on two-character string match 3

Status
Not open for further replies.

mwesticle

Programmer
Nov 19, 2003
51
US
Hi...
I have a file containing customer records that needs to be split into US and non-US customers. The records in this file are not delimited in any way. The country code appears in character positions (bytes) 312 and 313. If it equals 'US', then it goes to the US file, if not, it goes to a Foreign file. I don't know whether to use sort, awk, nawk, or anything else to solve my dilemma. Any takers??
 
nawk '{ file = (substr($0, 312, 2) == "US") ? "US.txt" : "nonUS.txt"; print $0 >> file}' myFile.txt

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
If the file is ASCII, try using sort (unix)
sort +0.311 -0.312 < infile > outfile
Assuming your character counts are 1-based.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top