filter a binary file and reduce 0x150a to 0x15

andrew clarke mail at ozzmosis.com
Tue Oct 19 14:04:52 UTC 2010


On Tue 2010-10-19 15:08:45 UTC+0200, Matthias Apitz (guru at unixarea.de) wrote:

> Before I programm it in C (or whatever), is there any normal shell tool
> to filter a (large) binary file and change any occurance of 0x150a to
> 0x15 (i.e. delete \n but only if it follows a char 0x15)?

I'd be personally more comfortable doing it in C or Python but I think
you can do this with tr -s.

Note: 0x15 == 25 octal; 0x0a == 12 octal.  I don't recall if it's
possible to use hex values in csh arguments - if so, what is the
syntax?

0:28 ozzmosis at blizzard [~/tmp]printf 'Hello\25\12world.\12' > blah

0:28 ozzmosis at blizzard [~/tmp]hd blah
00000000  48 65 6c 6c 6f 15 0a 77  6f 72 6c 64 2e 0a        |Hello..world..|
0000000e

0:28 ozzmosis at blizzard [~/tmp]tr -s '\25\12' '\25' < blah | hd
00000000  48 65 6c 6c 6f 15 77 6f  72 6c 64 2e 15           |Hello.world..|
0000000d

Regards
Andrew


More information about the freebsd-questions mailing list