Convert binary data to hexadecimal in a shell script

后端 未结 8 1620
日久生厌
日久生厌 2020-12-13 05:59

I want to convert binary data to hexadecimal, just that, no fancy formatting and all. hexdump seems too clever, and it \"overformats\" for me. I want to take x

8条回答
  •  旧巷少年郎
    2020-12-13 06:20

    If you need a large stream (no newlines) you can use tr and xxd (part of Vim) for byte-by-byte conversion.

    head -c1024 /dev/urandom | xxd -p | tr -d $'\n'
    

    Or you can use hexdump (POSIX) for word-by-word conversion.

    head -c1024 /dev/urandom | hexdump '-e"%x"'
    

    Note that the difference is endianness.

提交回复
热议问题