admin管理员组文章数量:1122826
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
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
Share Improve this question asked yesterday njamescouknjamescouk 1771 silver badge13 bronze badges 1 |2 Answers
Reset to default 2Neither 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'
With GNU tr
:
tr '\t' '\37'
\t: horizontal tab
\37: unit separator (octal 37, hex 1f)
See: man tr
本文标签: convert tab to unit separator using sed or tr with bashStack Overflow
版权声明:本文标题:convert tab to unit separator using sed or tr with bash - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736280933a1926158.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
sed
:sed 's#\x09#\x1f#g'
– Cyrus Commented yesterday