如何在Linux终端中删除CRLF字符(马车返回线馈电)?
我正在从Oracle数据库中接收一个简单的输出,由于某种原因,输出归结为新行,我无法删除该返回字符。
这就是我已经尝试的:
sed 's/^M//g'
sed 's/\r//g'
sed 's/\n//g'
sed 's/\r\n//g'
sed 's/\r$//'
tr -d '\r' < infile > outfile
sed -i.bak 's/\r$//g' <filename>
sed 's/\r$//g'
然后我尝试了dos2unix
,但仍然没有...
通过转换十六进制中的输出,我可以看到Misterious角色实际上是CRLF,但没有一个” CRLF删除“解决方案似乎有效。
- 正常输出
- hexa
预先感谢您的帮助! :)
I am receiving a simple output from an Oracle Database, for some reason the output goes down to a new line and I cannot remove that return character.
This is what I've already tried:
sed 's/^M//g'
sed 's/\r//g'
sed 's/\n//g'
sed 's/\r\n//g'
sed 's/\r$//'
tr -d '\r' < infile > outfile
sed -i.bak 's/\r$//g' <filename>
sed 's/\r$//g'
I then tried dos2unix
but still nothing...
By converting the output in hexadecimal I can see that the misterious character is actually a CRLF, but none of the previous "CRLF removing" solutions seem to work.
- The normal output
- The output converted in hexa
Thank you in advance for your help! :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
要删除CRLF字节,Perl中要容易得多:
或者您可以运行
sed
和tr
:c2 c2 a7
在UTF-8中对应于<<<<代码> u+00a7 或在Unicode中的部分标志
。指定两个字节以将其删除:
To remove the CRLF bytes, it's much easier in Perl:
Or you can run
sed
andtr
:C2 A7
in UTF-8 corresponds toU+00A7
orSECTION SIGN
in unicode.Specify both bytes to sed to remove it:
要删除所有线路供稿和运输返回字符:
任何POSIX TR也可以八分一:
To delete all line feed and carriage return characters:
Any POSIX tr can also take octals: