且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何从文本文件中删除换行符?

更新时间:2023-02-09 10:10:01

tr --delete '
' < yourfile.txt
tr -d '
' < yourfile.txt

如果这里发布的命令都不起作用,那么您除了用换行符分隔您的字段外,还有其他东西.可能您在文件中有 DOS/Windows 行结尾(尽管我希望 Perl 解决方案即使在这种情况下也能工作)?

If none of the commands posted here are working, then you have something other than a newline separating your fields. Possibly you have DOS/Windows line endings in the file (although I would expect the Perl solutions to work even in that case)?

试试:

tr -d "

" < yourfile.txt

如果这不起作用,那么您将不得不更仔细地检查您的文件(例如在十六进制编辑器中)以找出您想要删除的实际字符.

If that doesn't work then you're going to have to inspect your file more closely (e.g. in a hex editor) to find out what characters are actually in there that you want to remove.