Concatenating Files And Insert New Line In Between Files

前端 未结 7 1912
旧时难觅i
旧时难觅i 2020-11-29 16:48

I have multiple files which I want to concat with cat. Let\'s say

File1.txt 
foo

File2.txt
bar

File3.txt
qux

I want to conc

7条回答
  •  日久生厌
    2020-11-29 17:10

    In python, this concatenates with blank lines between files (the , suppresses adding an extra trailing blank line):

    print '\n'.join(open(f).read() for f in filenames),
    

    Here is the ugly python one-liner that can be called from the shell and prints the output to a file:

    python -c "from sys import argv; print '\n'.join(open(f).read() for f in argv[1:])," File*.txt > finalfile.txt
    

提交回复
热议问题