[英]How to get a single output file with N lines from N multiline files?
我正在寻找一种将多个多行文件连接成一个文件的有效方法-这是三个输入文件的示例:
1.txt :
a b
c d
2.txt :
e f
g
h
3.txt :
ijklmn
output.txt :
a b c d
e f g h
ijklmn
(用单个空格替换每个换行符)。 您可以推荐哪种方式?
使用BASH进行循环:
for i in [0-9]*.txt; do tr '\n' ' ' < "$i"; echo; done > output.txt
cat output.txt
a b c d
e f g h
ijklmn
如果要在每个换行符前去除一个结尾空间,请使用:
for i in [0-9]*.txt; do tr '\n' ' ' < "$i"; echo; done | sed 's/ *$//' > output.txt
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.