How to append contents of multiple files into one file

前端 未结 11 2083
既然无缘
既然无缘 2020-12-22 15:49

I want to copy the contents of five files to one file as is. I tried doing it using cp for each file. But that overwrites the contents copied from the previous file. I also

相关标签:
11条回答
  • 2020-12-22 16:34

    If all your files are named similarly you could simply do:

    cat *.log >> output.log
    
    0 讨论(0)
  • 2020-12-22 16:35
    for i in {1..3}; do cat "$i.txt" >> 0.txt; done
    

    I found this page because I needed to join 952 files together into one. I found this to work much better if you have many files. This will do a loop for however many numbers you need and cat each one using >> to append onto the end of 0.txt.

    0 讨论(0)
  • 2020-12-22 16:38

    if you have a certain output type then do something like this

    cat /path/to/files/*.txt >> finalout.txt
    
    0 讨论(0)
  • 2020-12-22 16:39

    If you want to append contents of 3 files into one file, then the following command will be a good choice:

    cat file1 file2 file3 | tee -a file4 > /dev/null
    

    It will combine the contents of all files into file4, throwing console output to /dev/null.

    0 讨论(0)
  • 2020-12-22 16:47

    You need the cat (short for concatenate) command, with shell redirection (>) into your output file

    cat 1.txt 2.txt 3.txt > 0.txt
    
    0 讨论(0)
提交回复
热议问题