Velvet Star Monitor

Standout celebrity highlights with iconic style.

news

Combine multiple text files into one file

Writer Matthew Harrington

I am using the unix pr command to combine multiple text files into one text file:

pr -F *files > newfile

Each 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!

0

4 Answers

To have empty lines betwen files:

cat file1 newline file2 newline file3 > newfile

Where 'newline' is file with empty line.

3

You can use the AWK utility:

awk 'FNR==1{print ""}{print}' *files > newfile

Source:

3
for file in *.txt; do (cat "${file}"; echo) >> concatenated.txt; done

The 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

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy