It is currently Fri May 25, 2018 8:57 am

Octal dump question

All times are UTC - 6 hours

Post new topic Reply to topic  [ 3 posts ] 
Author Message
 PostPosted: Tue Sep 21, 2010 9:25 pm   

Joined: Tue Sep 21, 2010 9:13 pm
Posts: 1
I have been trying to decipher something for a while now, and it eludes me...maybe you can help?

Here is the line of code:
`printf "%-24s" "${1}" | od -w99 -A n -tx1`

It is really just the "od" part, and the "-w99" that I cannot get. I believe it is formatting the ASCII string (that is what $1 contains) to an appropriate hex string, but I cannot verify.

The other question I have about this code is the "|" this really doing a bitwise OR on the string, or is it a separator?

Any help would be appreciated!


 PostPosted: Tue Sep 21, 2010 11:30 pm   
User avatar

Joined: Sun Jun 27, 2010 12:57 am
Posts: 192
-w99 is an option of od to set the width of the output. In this case the output can span up to 99 characters before wrapping to a newline.

The pipe character is not a bitwise OR, but an I/O pipe between 2 shell commands. The first command, printf, outputs a string of text which then in *nix terms gets 'piped' as the input for the second command, od, which reads and converts this input. This way you can chain a lot of 'filter' commands one after the other. f.e. cat "file.txt" | grep "my string" | sed "s/my/your/" | sort

 PostPosted: Wed Sep 22, 2010 5:50 am   

Joined: Wed Sep 22, 2010 5:35 am
Posts: 1
Thank you for that explanation patsie! It was very frustrating that I could not find specific information about that switch...

It occurred to me this morning that the "|" must be a separator within a printf statement, and that the function of the whole thing was to create a simple ASCII to hex conversion of the input. There must be a simpler way to do this, and knowing what is going on now is a step in the right direction.

Thanks again,

Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC - 6 hours

Who is online

Users browsing this forum: Google [Bot] and 7 guests

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  

BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group