Concatenating Files And Insert New Line In Between Files

前端 未结 7 1897
旧时难觅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:28

    This works in Bash:

    for f in *.txt; do cat $f; echo; done
    

    In contrast to answers with >> (append), the output of this command can be piped into other programs.

    Examples:

    • for f in File*.txt; do cat $f; echo; done > finalfile.txt
    • (for ... done) > finalfile.txt (parens are optional)
    • for ... done | less (piping into less)
    • for ... done | head -n -1 (this strips off the trailing blank line)
    0 讨论(0)
提交回复
热议问题