Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

convert tab to unit separator using sed or tr with bash

as title – I want to convert tabs in an input file / stdin to asciii unit separators on stdout / redirected file.

All of the following have no effect

tr 0x09 0x1f
tr '0x09' '0x1f'
sed  's#0x09#0x1f#g'
sed s#0x09#0x1f#g

have no effect

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Neither tr nor sed understand 0x09 and 0x1f. In bash, you can use the $'...' quotes with C-style backslash escape sequences. This style understands both \t and \x... notations.

printf 'a\tb\n' | sed $'s/\t/\x1f/g'
printf 'a\tb\n' | tr '\t' $'\x1f'
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading