Search code examples
linuxfileterminalvicat

How to combine multiple files in linux with delimiter seperation?


I'm trying to combine multiple files to 1 file using cat command. However I wish to add a separation line like "----" in between the file contents.

Is there a way we can achieve this with cat or any other tool?

cat file1 file2 file3 file4 > newfile

Solution

  • you can use the following command for combining multiple files with --- delimiter.

    awk 'FNR==1 && NR!=1 {print "---"}{print}' file1 file2 > newfile
    

    command is copied from this post of Unix stack excahnge https://unix.stackexchange.com/questions/163782/combine-two-text-files-with-adding-some-separator-between