如何用换行符替换:字符? [英] How do I replace : characters with newline?
问题描述
我看了一个非常相似的问题,但无法解决问题用以下方式替换逗号sed中的换行符
I looked at a very similar question but was unable to resolve the issue Replace comma with newline in sed
我正在尝试转换字符串中的:
个字符.这是我尝试过的:
I am trying to convert :
characters in a string. This is what I tried:
echo -e 'this:is:a:test' | sed "s/\:/'\n'/g"
,但这将n替换为:.我也尝试过tr,但结果相同.我相信-e在通过管道传输后不会被看到,因此无法识别新行.
but this replaces : with n. I tried tr too but had the same result. I believe the -e is not seen after being piped so new line is not recognized.
感谢您的帮助.
推荐答案
echo 'this:is:a:test' | tr : \\n
任何符合POSIX的tr 都将支持\n
转义顺序.但是,您需要注意引用或转义转义序列(上面的双反斜杠).
Any POSIX-compliant tr will support the \n
escape sequence. You need to take care to quote or escape the escape sequence, however (double backslash above).
echo的-e
参数对echo参数没有影响.
The -e
argument to echo has no effect on your argument to echo.
这篇关于如何用换行符替换:字符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!