如何在Linux终端中删除CRLF字符(马车返回线馈电)?

发布于 2025-02-11 09:54:47 字数 805 浏览 1 评论 0原文

我正在从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

”“在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 normal output

  • The output converted in hexa

The output converted in hexa

Thank you in advance for your help! :)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

∞觅青森が 2025-02-18 09:54:47

要删除CRLF字节,Perl中要容易得多:

perl -pe 's/\x0d\x0a//g'

或者您可以运行sedtr

sed 's/\r$//' file | tr -d '\n'

c2 c2 a7在UTF-8中对应于<<<<代码> u+00a7 或在Unicode中的部分标志

指定两个字节以将其删除:

sed 's/\xc2\xa7//g'

To remove the CRLF bytes, it's much easier in Perl:

perl -pe 's/\x0d\x0a//g'

Or you can run sed and tr:

sed 's/\r$//' file | tr -d '\n'

C2 A7 in UTF-8 corresponds to U+00A7 or SECTION SIGN in unicode.

Specify both bytes to sed to remove it:

sed 's/\xc2\xa7//g'
治碍 2025-02-18 09:54:47

要删除所有线路供稿和运输返回字符:

tr -d '\r\n' < old > new

任何POSIX TR也可以八分一:

tr -d '\015\012' < old > new

To delete all line feed and carriage return characters:

tr -d '\r\n' < old > new

Any POSIX tr can also take octals:

tr -d '\015\012' < old > new
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文