如何用换行符替换:字符? [英] How do I replace : characters with newline?

查看:105
本文介绍了如何用换行符替换:字符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看了一个非常相似的问题,但无法解决问题用以下方式替换逗号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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆