我想合并两个文件 cat file1 file2 > file3
。但它从新行开始。我不想要那个。我可以使用 tr 将所有新行替换为空格,但我不能这样做,因为文件中有我不想替换的新行。
最佳答案
您可以使用 head
和 -1
作为 -c
标志参数和 -q
head -c -1 -q file1 file2 > file3
head -c -1
将输出代码的最后 1 个字节之前的所有内容(在这种情况下,最后 1 个字节 - 结束行 - 将不包括在内)。 -q
是这样的,文件名不会像 head
那样在 head
多个文件时默认通过管道传输到 file3
.
或者,按照这个答案的建议 - bash cat multiple files content in to single string without newlines
,将其通过管道传输到 tr
:
tr -d "\n"
关于linux - 在没有换行的情况下用cat合并两个文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7746005/