使用tr将换行符替换为空格 [英] Using tr to replace newline with space
本文介绍了使用tr将换行符替换为空格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
具有sed
的输出:
http://sitename.com/galleries/83450
72-profile
这两个字符串应合并为一个,并用空格分隔,例如:
Those two strings should be merged into one and separated with space like:
http://sitename.com/galleries/83450 72-profile
两个字符串通过管道传递到tr
,以便用空格替换换行符:
Two strings are pipelined to tr
in order to replace newline with space:
tr '\n' ' '
它不起作用,结果与输入相同.
And it's not working, the result is the same as input.
用ASCII码'\032'
表示空格会导致将\n
替换为不可打印的字符.
Indicating space with ASCII code '\032'
results in replacing \n
with non-printable characters.
怎么了?我正在Windows上使用Git Bash.
What's wrong? I'm using Git Bash on Windows.
推荐答案
最好的猜测是您在Windows上,并且为Windows设置了行尾设置. 请参阅以下主题:如何更改行尾设置
Best guess is you are on windows and your line ending settings are set for windows. See this topic: How to change line-ending settings
或使用:
tr '\r\n' ' '
这篇关于使用tr将换行符替换为空格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文