Suppose I have a output in stdout like this:
e28f6001
e12fff16
2210
4679
df01
6c656873
How can I pipe this in bash so I can append \x for each byte. I want the the output like this:
\xe2\x8f\x60\x01\xe1\x2f\xff\x16\x22\x10 ...
tr -d '\n' < File | sed 's/.\{2\}/\\x&/g'
Remove newline first. Then substitute every 2 characters (.\{2\}) with \x followed by the 2 characters (& => the matched pattern which will be those 2 characters).
sed -e 's/../\\x&/g'though that won't join the lines.sed -r 's/([a-fA-F0-9]{2})/\\x\1/g' file | tr -d '\n'tr -d '\n '