如果我有这样一个文件:
hello n world
如何在解释转义序列的情况下打印文件内容,因此在终端中您可以看到:
hello
world
我试过cat file | xargs -I{} echo {}
,但打印的是hello n world
我想
echo 'hello\nworld' | xargs -I {} printf "%b" "{}"
就是你要找的。但是这需要你对通过管道发送的文本有一些控制,因为它需要双反斜杠。
printf
的%b
格式说明符扩展转义序列:
$ printf '%bn' "$(cat file)"
hello
world
从stdin中读取未修饰的cat
将做:
$ printf '%bn' "$(cat)"
hello
world