 |
 |
help with sed
|
 |
|
 |
|
Fresh-Faced Recruit
Join Date: Jan 2006
Status:
Offline
|
|
Hello,
I am having a problem using sed to substitute hex data in a file. I have no problem with using sed for simple substitution ie (sed s’/a/b/g’ file a > file b) (replace all a’s in file a with b’s). What I need to do is something like this (sed s’/\x20/\x30/g’ file a > file b) (where \x20 is the hex for ‘ ‘ and \x30 is the hex for ‘0’). Does anyone know the proper syntax for this?
Thanks.

|
|
|
| |
|
|
|
 |
|
 |
|
Grizzled Veteran
Join Date: Apr 2002
Location: case.edu
Status:
Offline
|
|
sed isn't really designed for working with binary data. You might have better luck with tr, which accepts the \xxx octal escapes (and maybe other types as well - check its man page).
Be sure to single-quote all your arguments so the shell doesn't eat the backslashes. You may wish to try your arguments with echo first if you aren't sure what's going on.
|
pb 1440x960 | 1.67, 1.5, 128, 80 | leopard
|
| |
|
|
|
 |
|
 |
|
Junior Member
Join Date: Jun 2005
Status:
Offline
|
|
You can get the list of octal, hex and decimal codes for use in the tr command by issuing a 'man ascii' in the CLI.
Walt
|
|
|
| |
|
|
|
 |
|
 |
|
Fresh-Faced Recruit
Join Date: Jan 2006
Status:
Offline
|
|
Thanks Guys,
tr worked great. 
|
|
|
| |
|
|
|
 |
|
 |
|
Grizzled Veteran
Join Date: Mar 2004
Status:
Offline
|
|
Originally Posted by duneomvs
I am having a problem using sed to substitute hex data in a file. I have no problem with using sed for simple substitution ie (sed s’/a/b/g’ file a > file b) (replace all a’s in file a with b’s). What I need to do is something like this (sed s’/\x20/\x30/g’ file a > file b) (where \x20 is the hex for ‘ ‘ and \x30 is the hex for ‘0’). Does anyone know the proper syntax for this?
While the answers above apply well to 'binary' data
if instead you were referring to text inside of a text file...
then all that was needed was to "escape the escape."
Sorta like this...
Code:
hostname:~ (501) $ echo \x20
x20
hostname:~ (502) $ echo \\x20
\x20
hostname:~ (503) $ echo '\x20'
\x20
hostname:~ (504) $ echo '\x20' | sed 's/\\x20/\\x30/g'
\x30
hostname:~ (505) $
Maybe without slashes it's easier to see:
sed 's:\\x20:\\x30:g'
|
|
-HI-
|
| |
|
|
|
 |
 |
|
 |
|
|
|
|
|

|
|
 |
Forum Rules
|
 |
 |
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
 |
 |
 |
 |
|
 |