我正在使用以下命令合并多个文件:paste -d"\n \n" -s *.md > big-markdown-file.md
。
我的问题是合并的文件之间只有一个换行符:
# This is the start of
Lorem ipsum dolor sit amet, te eos solet copiosae deterruisset, mea eu augue postulant temporibus. Sit ex definiebas referrentur. This is the end of file1.
# This is the start of File2.md
Lorem ipsum dolor sit amet, te eos solet copiosae deterruisset, mea eu augue postulant temporibus. Sit ex definiebas referrentur. This is the end of file2.
# This is the start of File3.md
Lorem ipsum dolor sit amet, te eos solet copiosae deterruisset, mea eu augue postulant temporibus. Sit ex definiebas referrentur. This is the end of file3.
在处理减价时,这会导致问题,将 lorem ipsum 段落变成标题。有没有一种方法可以在最终文件中的各个粘贴之间引入两个换行符,以便输出类似这样的内容:
# This is the start of
Lorem ipsum dolor sit amet, te eos solet copiosae deterruisset, mea eu augue postulant temporibus. Sit ex definiebas referrentur. This is the end of file1.
# This is the start of File2.md
Lorem ipsum dolor sit amet, te eos solet copiosae deterruisset, mea eu augue postulant temporibus. Sit ex definiebas referrentur. This is the end of file2.
# This is the start of File3.md
Lorem ipsum dolor sit amet, te eos solet copiosae deterruisset, mea eu augue postulant temporibus. Sit ex definiebas referrentur. This is the end of file3.
答案 0 :(得分:1)
也许“作弊”并创建一个虚拟文件?
$ touch dummy
$ paste -d"\n" -s *.md dummy > big-markdown-file.md
$ rm dummy # :)
我认为这将导致paste
尝试消耗空文件中的下一行“失败”,而是创建一个空行。
实际上,对于文件列表,您必须为每个文件创建一个虚拟文件:
$ # create dummy files
$ for f in *.md; do echo $f; touch ${f}_dummy.md; done
$ # create the result files
$ paste -d"\n" -s *.md > big-markdown-file.md
$ # remove dummy files
$ find -name '*dummy.md' -delete