Create a file named as test
containing the following content:
0123456789abcdef0123456789abcdef
I want to remove the first 0
with the use of xxd. Open it with vim -b test
then run :%!xxd
inside vim. The result is:
0000000: 3031 3233 3435 3637 3839 6162 6364 6566 0123456789abcdef
0000010: 3031 3233 3435 3637 3839 6162 6364 6566 0123456789abcdef
0000020: 0a .
Then I remove the hex code 30
for the first 0
:
0000000: 31 3233 3435 3637 3839 6162 6364 6566 0123456789abcdef
0000010: 3031 3233 3435 3637 3839 6162 6364 6566 0123456789abcdef
0000020: 0a .
Then I run :%!xxd -r
to read the hex back. The result is:
^@23456789abcdef^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@
The result is garbled. I know that the reason is the above content is not a valid xxd input. If I remove the line numbers and the text part:
31 3233 3435 3637 3839 6162 6364 6566
3031 3233 3435 3637 3839 6162 6364 6566
0a
The I run :%!xxd -r -p
to read the hex back. And the result is correct:
123456789abcdef0123456789abcdef
Is there a better way to do this job with the use of vim and xxd? A better way means less editing to make a valid input for xxd -r
.