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

sorting and extracting records from a file

Status
Not open for further replies.

jhawktim

IS-IT--Management
Oct 28, 2002
1
US
I have a system that generates a daily file that contains an average of 175,000 records per day. These records are fixed length ASCII. I am looking for a script of some kind that I can put in the cron that will separate out the records that start with 0 in the first 5 positions and put those records in a separate output file while leaving the original file intact. I'm sure there is a way to do this but being very novice, I don't know it. Thanks for any help you can give me. pflugradtt@birch.com
 
I would use awk to do this.

The script could probably be a simple 1 liner like:

awk '{if (substr($0,1,5)=="00000") print $0}' inputfile >outputfile

Refer to the "awk" man pages for details on awk scripting.
 
Or, presuming the records are on separate lines in the file, simply:

[tt] grep ^00000 inputfile > outputfile[/tt]

Annihilannic Annihilannic.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top