ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
There's a nice utility that comes with Vim called xxd. It is script-friendly, and (unlike od or hexdump) has the ability to go back and forth (with the revert option).
For example, you could have something like:
Code:
... | xxd -g 1 -c 1 | awk ...
Where there are three fields you can access in awk. $1 is the offset (in hex), $2 is the two-digit hex representation of a byte, and $3 is the ASCII representation of the byte (or just a period for nonprintable characters).
For going back, just do something like:
Code:
... | xxd -p -s -
The only formatting restrictions on the input is that single bytes appear together as two-digit numbers. It doesn't care about formatting or whitespace (the -p is for plain).
I guess xxd's not as portable as hexdump or od, but it is probably more portable than uni2ascii (i.e., is more likely to be found installed on a *nix machine than uni2ascii).
Distribution: Quad boot :: Windows vista 64-bit | Vector Linux | Slackware 13.0 64-Bit | Linux Mint 7 64-bit
Posts: 127
Thanked: 0
Original Poster
Quote:
Originally Posted by osor
I guess xxd's not as portable as hexdump or od, but it is probably more portable than uni2ascii (i.e., is more likely to be found installed on a *nix machine than uni2ascii).
Thats true, but I'm not that concerned about portability, (I'm using slax based Back|Track and adding modules is easy) and I'm not doing anything really important, just learning to write my own snort rules and I was getting tired to visit online hex translators
But anyways, that ascii2hex is working nicely with my script so thanks again.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
Advertisement
Oracle Magazine contains technology strategy articles, sample code, tips, Oracle and partner news, how to articles for developers and DBAs, and more. Click Here to receive a complimentary subscription courtesy of LQ.