16

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 4

16

To have empty lines betwen files:

cat file1 newline file2 newline file3 > newfile

Where 'newline' is file with empty line.

3
  • Can you clarify how to make the file newline? Some text edtiors will automatically append an end-of-line character to the last line, and others will not, so some people may experience problems making this file properly. To put this another way: does a zero-length file have zero lines, or one line? Jul 11, 2013 at 21:49
  • vim newline in vim :wq Thats it. Jul 12, 2013 at 5:20
  • 1
    As long as I see, "cat" puts new line automatically between each file.
    – myuce
    Nov 28, 2016 at 11:18
11

You can use the AWK utility:

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

Source: https://stackoverflow.com/questions/1653063/how-do-i-include-a-blank-line-between-files-im-concatenating-with-cat

3
  • thank you for you suggestion. however, -T isn't being recognized. i'm working on mac os x if that matters.
    – janet
    Jul 11, 2013 at 5:20
  • unfortunately, -t creates the same type of file that cat does, no break between text files read in.
    – janet
    Jul 11, 2013 at 6:06
  • thank you Radu. that just about gets me what i want! sorry, i realize now that i am posting to the wrong place, as i see the notification about being off-topic. i thank you for you help!
    – janet
    Jul 11, 2013 at 16:57
2

You can use cat to dump the text of files into one file with:

cat file1 file2 file3 > newfile
2
  • 2
    Unfortunately cat doesn't fulfill any of the other requirements. Jul 11, 2013 at 4:57
  • 1
    yes, thank you. but cat just lists the contents of each file without the original text file name and it also lists the contents of each file one after another with no break in between. i need at least 1 blank line between the contents of each text file in the new one big file.
    – janet
    Jul 11, 2013 at 5:23
2
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 must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .