3

To create sample file with cat.

cat > /tmp/test.txt <<EOF
> X1
> X22
> X333
> X4444
> EOF

To check the content in sample file.

cat  /tmp/test.txt
X1
X22
X333
X4444

To make a hexdump with xxd.

xxd   /tmp/test.txt
0000000: 5831 0a58 3232 0a58 3333 330a 5834 3434  X1.X22.X333.X444
0000010: 340a  

How to make a hexdump line by line with xxd in such way as below:

58 31 0a
58 32 32 0a
58 33 33 33 0a
58 34 34 34 34 0a
showkey
  • 482
  • 42
  • 140
  • 295

3 Answers3

3
$ xxd  -ps </tmp/test.txt|sed -e 's/\(..\)/\1 /g' -e 's/0a /0a\n/g'
58 31 0a
58 32 32 0a
58 33 33 33 0a
58 34 34 34 34 0a 
Ipor Sircer
  • 3,069
  • 3
  • 10
  • 15
2

After all I found the hexdump tool in combination with sed the best solution:

hexdump -v -e '/1 "%02x "' /tmp/test.txt | sed 's/0a /0a\n/g'
hek2mgl
  • 152,036
  • 28
  • 249
  • 266
0

Please download it and save as /home/urls.csv.

sample file to test

To test with
hexdump -v -e '/1 "%02x "' /home/urls.csv | sed 's/0a /0a\n/g'

enter image description here

To test with
xargs -I'{}' bash -c 'xxd <<< "${1}"' -- '{}' < /home/urls.csv

enter image description here

To test with
xargs -I'{}' bash -c 'hd <<< "${1}"' -- '{}' < /home/urls.csv enter image description here

To test with

xxd  -ps </home/urls.csv |sed -e 's/\(..\)/\1 /g' -e 's/0a /0a\n/g'

It is clear that Ipor Sircer's answer is no enough robustness for long files.

enter image description here

showkey
  • 482
  • 42
  • 140
  • 295