filter a binary file and reduce 0x150a to 0x15

Karl Vogel vogelke+unix at
Wed Oct 20 01:49:22 UTC 2010

>> On Tue, 19 Oct 2010 15:08:45 +0200, 
>> Matthias Apitz <guru at> said:

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

   This seems to work, depending on your definition of normal:

   me% od -c blah
   0000000 025 025   H   e   l   l   o 025  \n   w   o   r   l   d   .  \n

   me% perl -0pe 's/\025\n/\025/g;' < blah | od -c
   0000000 025 025   H   e   l   l   o 025   w   o   r   l   d   .  \n

   The "-0" says read null-terminated lines, so if your binary file is big
   enough and has few enough nulls, you could chew up a diaper-load of memory.

Karl Vogel                      I don't speak for the USAF or my company

A raccoon tangled with a 23,000 volt line today.  The results blacked
out 1400 homes and, of course, one raccoon.               --Steel City News

More information about the freebsd-questions mailing list