Re: filter a binary file and reduce 0x150a to 0x15

2010-10-20 Thread andrew clarke
On Tue 2010-10-19 21:21:00 UTC-0400, Karl Vogel (vogelke+u...@pobox.com) wrote:

me% perl -0pe 's/\025\n/\025/g;'  blah | od -c

Nitpicking a little, but Perl isn't part of the FreeBSD base any more.
Most FreeBSD users probably have it installed, though (perhaps as a
dependency)...
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org


Re: filter a binary file and reduce 0x150a to 0x15

2010-10-19 Thread Matthias Apitz
El día Tuesday, October 19, 2010 a las 09:24:34AM -0400, Jerry McAllister 
escribió:

 On Tue, Oct 19, 2010 at 03:08:45PM +0200, Matthias Apitz wrote:
 
  
  Hello,
  
  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)?
 
 Can you manage it with tr(1)  ?

Not as I read its man page; maybe you could give a concrete example?
Thanks

matthias
-- 
Matthias Apitz
t +49-89-61308 351 - f +49-89-61308 399 - m +49-170-4527211
e g...@unixarea.de - w http://www.unixarea.de/
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org


Re: filter a binary file and reduce 0x150a to 0x15

2010-10-19 Thread Matthias Apitz
El día Wednesday, October 20, 2010 a las 12:36:44AM +1100, andrew clarke 
escribió:

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

me too;

 
 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 ozzmo...@blizzard [~/tmp]printf 'Hello\25\12world.\12'  blah
 
 0:28 ozzmo...@blizzard [~/tmp]hd blah
   48 65 6c 6c 6f 15 0a 77  6f 72 6c 64 2e 0a|Hello..world..|
 000e
 
 0:28 ozzmo...@blizzard [~/tmp]tr -s '\25\12' '\25'  blah | hd
   48 65 6c 6c 6f 15 77 6f  72 6c 64 2e 15   |Hello.world..|
 000d

I saw this, but this has the side affect to reduce any occourance of a
duouble 0x1515 to 0x15:

g...@current:~ printf '\25\25Hello\25\12world.\12'  blah
g...@current:~ hd blah
  15 15 48 65 6c 6c 6f 15  0a 77 6f 72 6c 64 2e 0a |..Hello..world..|
0010
g...@current:~ tr -s '\25\12' '\25'  blah | hd
  15 48 65 6c 6c 6f 15 77  6f 72 6c 64 2e 15 |.Hello.world..|

Thanks anyway

matthias

-- 
Matthias Apitz
t +49-89-61308 351 - f +49-89-61308 399 - m +49-170-4527211
e g...@unixarea.de - w http://www.unixarea.de/
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org


Re: filter a binary file and reduce 0x150a to 0x15

2010-10-19 Thread Jerry McAllister
On Tue, Oct 19, 2010 at 03:08:45PM +0200, Matthias Apitz wrote:

 
 Hello,
 
 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)?

Can you manage it with tr(1)  ?

jerry


 
 Thanks
 
   matthias
 -- 
 Matthias Apitz
 t +49-89-61308 351 - f +49-89-61308 399 - m +49-170-4527211
 e g...@unixarea.de - w http://www.unixarea.de/
 ___
 freebsd-questions@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/freebsd-questions
 To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org


Re: filter a binary file and reduce 0x150a to 0x15

2010-10-19 Thread andrew clarke
On Tue 2010-10-19 15:08:45 UTC+0200, Matthias Apitz (g...@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 ozzmo...@blizzard [~/tmp]printf 'Hello\25\12world.\12'  blah

0:28 ozzmo...@blizzard [~/tmp]hd blah
  48 65 6c 6c 6f 15 0a 77  6f 72 6c 64 2e 0a|Hello..world..|
000e

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

Regards
Andrew
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org


Re: filter a binary file and reduce 0x150a to 0x15

2010-10-19 Thread Karl Vogel
 On Tue, 19 Oct 2010 15:08:45 +0200, 
 Matthias Apitz g...@unixarea.de 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
   000 025 025   H   e   l   l   o 025  \n   w   o   r   l   d   .  \n
   020

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

   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
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org