12

Can I tell xxd to not print any line breaks in its output and have my dump as one continuous line?

[user@localhost] : ~ $ echo -n "this is a long line and xxd is going to take multiple lines to print it" | xxd -p
746869732069732061206c6f6e67206c696e6520616e6420787864206973
20676f696e6720746f2074616b65206d756c7469706c65206c696e657320
746f207072696e74206974
  • 5
    You could simply use tr to delete the newlines, e.g. ... | xxd -p | tr -d \\n – don_crissti Jul 26 '15 at 23:12
  • It depends on what you need it for, but one handy option of xxd is that it ignores whitespace for the reverse -r of its postcript/plain -p dump (or any plain hexdump for that matter). eg. The following line wraps with \n, but the reversed output is exactly what was input: echo {1..14} | xxd -p | xxd -p -r produces output: 1 2 3 4 5 6 7 8 9 10 11 12 13 14\n – the \n is from the echo – Peter.O Jul 27 '15 at 0:20
  • 1
    You can also use hexdump -v -e '/1 "%02X"' instead of xxd. – dirkt Oct 10 '16 at 16:29
13

What you need is the -c option.

# echo -n "this is a long line and xxd will print it as one line" | xxd -p -c 1000000

746869732069732061206c6f6e67206c696e6520616e64207878642077696c6c207072696e74206974206173206f6e65206c696e65

Here is some info from the documentation:

-c cols | -cols cols format octets per line. Default 16 (-i: 12, -ps: 30, -b: 6). Max 256.

Documentation says that the max value for "c" parameter is 256, but I tried greater values and it worked. Check it out:

# xxd -c 1000000 -p -l 1000000 /dev/urandom | wc -c
2000001

Here I dump one million bytes from /dev/random and I get a string of 2 million + 1 characters. Each byte from /dev/random is represented by 2 characters and additional byte is the final newline.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.