Combine multiple text files into one file
Matthew Harrington
I am using the unix pr command to combine multiple text files into one text file:
pr -F *files > newfileEach file is a different length, a different number of lines. I am mostly happy with the result, I like that it includes the name of the original text file followed by the contents of that file. However, I would like to eliminate the blank lines in between the name of the original text file and it's contents. I only want blank lines between the different text files to separate each. Also, it prints the character ^L after the contents of each text file, and I would like to eliminate that character.
Each file read in is also given a 'page' number. Only one file is longer than the 66 line default. that file ends up being spit into 2 'pages', and is split into 2 sections divided by blank lines. Is it possible to write that text in continuously without it being split?
Thank you for any help!
04 Answers
To have empty lines betwen files:
cat file1 newline file2 newline file3 > newfileWhere 'newline' is file with empty line.
3You can use the AWK utility:
awk 'FNR==1{print ""}{print}' *files > newfileSource:
3for file in *.txt; do (cat "${file}"; echo) >> concatenated.txt; doneThe above will append the contents of eacb txt file into concatenated.txt adding a new line between them.
You can use cat to dump the text of files into one file with:
cat file1 file2 file3 > newfile 2