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

Change column in binary file to check contents; Write binary

Status
Not open for further replies.

txwaiting4u

Programmer
Jun 28, 2002
17
US
I have a binary file that I am splitting based on a particular field in the file; it's a one character field. The field in ascii (text) would be a 1 or a 2. However, I can't check for a 1 or a 2 because it is in binary. How do I check for a 1 or 2 yet write out the output files in binary?

I tried dd to convert the file to ascii first but that didn't work. I would prefer to check the field by converting it to ascii in a variable which wouldn't modify the file at all. Anyone know of a possible solution? Thanks!
 
This seems to work:

Code:
awk '
        BEGIN { RS=ORS=1 }
        {
                filename=sprintf("file.%05d",++n)
                print > filename
        }
' inputfilename

Note that this will put a record separater at the end of every file though. You could change ORS to "" if you don't want that.

Annihilannic.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top