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

How to strip off binary data? 3

Status
Not open for further replies.

praise12

IS-IT--Management
Mar 17, 2002
17
US
I'm a new learner of shell programming, I have some files coming in with binary data which I need to strip off, but I don't know how. Any help will be appreciated.
Thanks,
 
Hi
Do you know the character positions of the binary data or what kind of binary data?
 
The binary data came in across the file. But, the file is always in fixed length file. There are different type of binary data came in each time and we considered those are bad data.
I think what I need is to write a script to strip of all the nonprintable characters, does this make sense?
Thanks so much..
 
praise12:

Not guaranteeing this because if you're binary data over writes you EOL, octal \012, you may have a problem reading the data. Here's a small example:

1) Given data file, file.1, which looks like this:
aABCd

tr -dc '\012\101\102\103' < file.1 > new.file

this example says to delete all characters, but
LF - octal \012
A - octal \101
B - octal \102
C - octal \103

new.file should look like:

ABC

lower case a and d were deleted.

Do a man ascii and you'll see a listing of the ascii character set in octal. expand the command I've given you to choose the values you want. You'll probably want to go to \177.

If this doesn't do it, you'll probably have to write a &quot;C&quot; program. Use the low-level open function.

Regards,

Ed
Schaefer
 
You can use this sed command to replace non-printable characters by a space :

sed -e 's/[^[:print:]]/ /g' input_file Jean Pierre.
 
The strings command should work too. Read the man pages, especially on -n, for its usage and limitations.

Cheers,
ND
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top