Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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!

share|improve this question

3 Answers 3

up vote 4 down vote accepted

You can use the AWK utility:

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

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

share|improve this answer
    
thank you for you suggestion. however, -T isn't being recognized. i'm working on mac os x if that matters. –  janet Jul 11 '13 at 5:20
    
unfortunately, -t creates the same type of file that cat does, no break between text files read in. –  janet Jul 11 '13 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 '13 at 16:57

To have empty lines betwen files:

cat file1 newline file2 newline file3 > newfile

Where 'newline' is file with empty line.

share|improve this answer
    
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? –  Eliah Kagan Jul 11 '13 at 21:49
    
vim newline in vim :wq Thats it. –  Darius Žitkevičius Jul 12 '13 at 5:20

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

cat file1 file2 file3 > newfile
share|improve this answer
1  
Unfortunately cat doesn't fulfill any of the other requirements. –  Ignacio Vazquez-Abrams Jul 11 '13 at 4:57
    
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 '13 at 5:23

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.