Skip to content

Instantly share code, notes, and snippets.

@flashvoid
Last active April 7, 2017 05:07
Show Gist options
  • Save flashvoid/0965307f6f63612e363521c46229bbe6 to your computer and use it in GitHub Desktop.
Save flashvoid/0965307f6f63612e363521c46229bbe6 to your computer and use it in GitHub Desktop.
format hex string using awk
#!/bin/sh
awk '{
split($0, chars, "");
for (i=1; i<=length($0); i++) {
if (flagInLine == 0) { printf ("%-5d", i/32); flagInLine=1 }
printf("%s%s ", chars[i], chars[i+1]);
if ((i+1) % 32 == 0) { flagInLine=0; printf "\n"}
i++
}
}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment