1751978 Members
4641 Online
108784 Solutions
New Discussion юеВ

Re: od usage

 
Joydeep_1
Occasional Advisor

od usage

Hi Gurus,

Suppose I have text file & file content is as below.
$cat test
abcd efgh
Now I want to replace \n with \o during usage of od. It is working perfectly.
od -c test | sed 's/\\n/\\o/g'
but if I redirect that output in any test file then I would get octal output . I would not get same character what I had in test. Is it possible to convert from octal to character.

Like it would show as like
abcd efgh\o


6 REPLIES 6
Justo Exposito
Esteemed Contributor

Re: od usage

Hi Sandip,

Do you try this?:

sed 's/$/\\o/g' test > test.out

Regards,

Justo.
Help is a Beatiful word
Robin Wakefield
Honored Contributor

Re: od usage

Hi Sandip,

What do you mean by "redirect the output" gives you octal?

Thanks, Robin.
Joydeep_1
Occasional Advisor

Re: od usage

Actually I want to see that plain test file's octal value & after that I want to change octal value \n to \o & want to see what it affect in that test file. But after converting character to octal , how can I reconvert it from octal character ?
Steven Gillard_2
Honored Contributor

Re: od usage

Not sure I understand completely, but I'm guessing you want to simply replace all \n chars in a file with \0 (you've written \o but I'm not sure what charater that represents??). Is this correct?

If so, try the tr command:

$ tr '\n' '\0' < input > output

Regards,
Steve
harry d brown jr
Honored Contributor

Re: od usage

Sandip,

Steven's example of "tr" works. It was confusing when you posted "\o", as it appears you are trying to replace newlines (\n) with nulls (\0 [slash zero] not \o).

live free or die
harry
Live Free or Die
Darrell Allen
Honored Contributor

Re: od usage

Hi Sandip,

Here's a little more info...

od is not a text conversion tool - it is a tool used to display the contents of a file and is particularly helpful for determining what unprintable characters may be in a file.

The output of od is always an ascii file (formatted for ease of reading) whether it's to stdout or redirected to a disk file. Test this:
od -c test | sed 's/\\n/\\o/g' >od.output
file od.output
cat od.output
ls -l od.output
od -c od.output

Also, -c argument of od is for ascii representation. To see the octal representation of an ascii test file (like your test file) use -b. Man od for more options.

Darrell
"What, Me Worry?" - Alfred E. Neuman (Mad Magazine)