in reply to keeping spaces
I wonder if tr might help you. Particularly, the c flag complements the characters specified so, you can get rid of anything that isn't a newline (0x0a) and the range of printable characters from space (0x20) through ~ (0x7e). Also include return (0x0d) if on Windows.
$ perl -le ' > $str = qq{\x00\x03abc xyz\n\x00\x00\x0912 34 56\x05\n}; > print for map sprintf( q{0x%02x}, ord ), split m{}, $str; > print q{-} x 20; > $str =~ tr{\x0a\x20-\x7e}{}cd; > print for map sprintf( q{0x%02x}, ord ), split m{}, $str;' 0x00 0x03 0x61 0x62 0x63 0x20 0x78 0x79 0x7a 0x0a 0x00 0x00 0x09 0x31 0x32 0x20 0x33 0x34 0x20 0x35 0x36 0x05 0x0a -------------------- 0x61 0x62 0x63 0x20 0x78 0x79 0x7a 0x0a 0x31 0x32 0x20 0x33 0x34 0x20 0x35 0x36 0x0a $
I hope this is helpful.
Cheers,
JohnGG
Update: Fixed typo.
|
|---|