I've a long hex string 00121eafc5800020 ... etc.
Is there an easy way I can split these with a space per hex coded byte so I get 00 12 1e af c5 80 00 20 in vim (or another easily accessible tool)
Super User is a question and answer site for computer enthusiasts and power users. It only takes a minute to sign up.
Sign up to join this community$ sed 's/\(..\)/\1 /g' <<< '1234567890'
12 34 56 78 90
Try this key sequence (from the start of the number):
q1lxPpr lq@1@1@1@1@1@1@1@1
(etc. or say, 20@1)
In vim
, you can use :s/\([0-9a-f][0-9a-f]\)/\1 /g
to do what you want. To test this, you can use the following command:
dd bs=512 if=/dev/urandom count=2 2>/dev/null | xxd -p | tr -d '\n' | vim -
Then in vim
, use :s/\([0-9a-f][0-9a-f]\)/\1 /g
to add a space after every pair of hex-characters. Here's a small example:
$ dd bs=32 if=/dev/urandom count=1 2>/dev/null | xxd -p | tr -d '\n' | vim -
6aad5f800a739fadbc3e2312230daeca8055491577b0e0d75a37bb3777f0a3e0
:s/\([0-9a-f][0-9a-f]\)/\1 /g
6a ad 5f 80 0a 73 9f ad bc 3e 23 12 23 0d ae ca 80 55 49 15 77 b0 e0 d7 5a 37 bb 37 77 f0 a3 e0
:%s/\x\x/& /g
is enough.
If you want to cut into several lines, you can also apply this :substitute
first.
:%s/\x\{16}/&\r/g
Or if you prefer a one-liner (I'm not sure this is a better solution here)
:%s/\x\{16}/\=substitute(submatch(0), '\x\x', '& ', 'g')."\n"/g