Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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}'
like image 513
0x90 Avatar asked Mar 21 '13 16:03

0x90


People also ask

How do I read a hex dump?

The address of a hex dump counts tracks the number of bytes in the data and offsets each line by that number. So the first line starts at offset 0, and the second line represents the number 16, which is how many bytes precede the current line.

What is the uses of the hex dump command?

The hd or hexdump command in Linux is used to filter and display the specified files, or standard input in a human readable specified format. For example, if you want to view an executable code of a program, you can use hexdump to do so.

How do you reverse a hex dump?

Better alternative to create hexdumps in the first place Will print a hexadecimal dump, grouping digits as single bytes ( -tx1 ), with no Address prefixes ( -An , similar to xxd -p ) and without abbreviating repeated sections as * ( -v ). You can reverse such a dump using xxd -r -p .

What is dump in hex editor?

In computing, a hex dump is a hexadecimal view (on screen or paper) of computer data, from memory or from a computer file or storage device. Looking at a hex dump of data is usually done in the context of either debugging or reverse engineering.


2 Answers

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.
like image 108
0x90 Avatar answered Oct 19 '22 18:10

0x90


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.)

like image 42
chepner Avatar answered Oct 19 '22 19:10

chepner