如何从文本文件中删除换行符? [英] How do I remove newlines from a text file?
问题描述
我有以下数据,需要全部放在一行.
I have the following data, and I need to put it all into one line.
我有这个:
22791
;
14336
;
22821
;
34653
;
21491
;
25522
;
33238
;
我需要这个:
22791;14336;22821;34653;21491;25522;33238;
编辑
这些命令都不能完美运行.
EDIT
None of these commands is working perfectly.
他们中的大多数让数据看起来像这样:
Most of them let the data look like this:
22791
;14336
;22821
;34653
;21491
;25522
推荐答案
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.
这篇关于如何从文本文件中删除换行符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!