How to print only the hex values from hexdump without line numbers or ASCII table? [duplicate]

微笑、不失礼 提交于 2019-12-20 08:46:07

问题


following Convert decimal to hexadecimal in UNIX shell script

I am trying to print only the hex values from hexdump, i.e. don't print the lines numbers and the ASCII table.

But the following command line doesn't print anything:

hexdump -n 50 -Cs 10 file.bin |  awk '{for(i=NF-17; i>2; --i) print $i}'

回答1:


You can specify the exact format that you want hexdump to use for output, but it's a bit tricky. Here's the default output, minus the file offsets:

hexdump -e '16/1 "%02x " "\n"' file.bin

(To me, it looks like this would produce an extra trailing space at the end of each line, but for some reason it doesn't.)




回答2:


Using xxd is better for this job:

xxd -p -l 50 -seek 10 file.bin

From man xxd:

xxd - make a hexdump or do the reverse.

    -p | -ps | -postscript | -plain
        output in postscript continuous hexdump style. Also known as plain hexdump style.

    -l len | -len len
        stop after writing <len> octets.

    -seek offset
        When used after -r: revert with <offset> added to file positions found in hexdump.



回答3:


As an alternative, consider using xxd -p file.bin.




回答4:


First of all, remove -C which is emitting the ascii information.

Then you could drop the offset with

hexdump -n 50 -s 10 file.bin | cut -c 9-


来源:https://stackoverflow.com/questions/15553493/how-to-print-only-the-hex-values-from-hexdump-without-line-numbers-or-ascii-tabl

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!