Combine multiple text files into one file
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!
command-line
add a comment |
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!
command-line
add a comment |
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!
command-line
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!
command-line
command-line
edited Jul 11 '13 at 5:34
Radu Rădeanu
116k34247323
116k34247323
asked Jul 11 '13 at 4:38
janetjanet
169227
169227
add a comment |
add a comment |
4 Answers
4
active
oldest
votes
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
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
add a comment |
To have empty lines betwen files:
cat file1 newline file2 newline file3 > newfile
Where 'newline' is file with empty line.
Can you clarify how to make the filenewline
? 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
As long as I see, "cat" puts new line automatically between each file.
– myuce
Nov 28 '16 at 11:18
add a comment |
You can use cat
to dump the text of files into one file with:
cat file1 file2 file3 > newfile
2
Unfortunatelycat
doesn't fulfill any of the other requirements.
– Ignacio Vazquez-Abrams
Jul 11 '13 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 '13 at 5:23
add a comment |
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.
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "89"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f318777%2fcombine-multiple-text-files-into-one-file%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
4 Answers
4
active
oldest
votes
4 Answers
4
active
oldest
votes
active
oldest
votes
active
oldest
votes
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
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
add a comment |
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
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
add a comment |
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
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
edited May 23 '17 at 12:39
Community♦
1
1
answered Jul 11 '13 at 5:03
Radu RădeanuRadu Rădeanu
116k34247323
116k34247323
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
add a comment |
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
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
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
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
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
add a comment |
To have empty lines betwen files:
cat file1 newline file2 newline file3 > newfile
Where 'newline' is file with empty line.
Can you clarify how to make the filenewline
? 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
As long as I see, "cat" puts new line automatically between each file.
– myuce
Nov 28 '16 at 11:18
add a comment |
To have empty lines betwen files:
cat file1 newline file2 newline file3 > newfile
Where 'newline' is file with empty line.
Can you clarify how to make the filenewline
? 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
As long as I see, "cat" puts new line automatically between each file.
– myuce
Nov 28 '16 at 11:18
add a comment |
To have empty lines betwen files:
cat file1 newline file2 newline file3 > newfile
Where 'newline' is file with empty line.
To have empty lines betwen files:
cat file1 newline file2 newline file3 > newfile
Where 'newline' is file with empty line.
answered Jul 11 '13 at 6:55
Darius ŽitkevičiusDarius Žitkevičius
892
892
Can you clarify how to make the filenewline
? 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
As long as I see, "cat" puts new line automatically between each file.
– myuce
Nov 28 '16 at 11:18
add a comment |
Can you clarify how to make the filenewline
? 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
As long as I see, "cat" puts new line automatically between each file.
– myuce
Nov 28 '16 at 11:18
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
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
vim newline in vim :wq Thats it.
– Darius Žitkevičius
Jul 12 '13 at 5:20
As long as I see, "cat" puts new line automatically between each file.
– myuce
Nov 28 '16 at 11:18
As long as I see, "cat" puts new line automatically between each file.
– myuce
Nov 28 '16 at 11:18
add a comment |
You can use cat
to dump the text of files into one file with:
cat file1 file2 file3 > newfile
2
Unfortunatelycat
doesn't fulfill any of the other requirements.
– Ignacio Vazquez-Abrams
Jul 11 '13 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 '13 at 5:23
add a comment |
You can use cat
to dump the text of files into one file with:
cat file1 file2 file3 > newfile
2
Unfortunatelycat
doesn't fulfill any of the other requirements.
– Ignacio Vazquez-Abrams
Jul 11 '13 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 '13 at 5:23
add a comment |
You can use cat
to dump the text of files into one file with:
cat file1 file2 file3 > newfile
You can use cat
to dump the text of files into one file with:
cat file1 file2 file3 > newfile
answered Jul 11 '13 at 4:51
Atari911Atari911
52436
52436
2
Unfortunatelycat
doesn't fulfill any of the other requirements.
– Ignacio Vazquez-Abrams
Jul 11 '13 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 '13 at 5:23
add a comment |
2
Unfortunatelycat
doesn't fulfill any of the other requirements.
– Ignacio Vazquez-Abrams
Jul 11 '13 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 '13 at 5:23
2
2
Unfortunately
cat
doesn't fulfill any of the other requirements.– Ignacio Vazquez-Abrams
Jul 11 '13 at 4:57
Unfortunately
cat
doesn't fulfill any of the other requirements.– Ignacio Vazquez-Abrams
Jul 11 '13 at 4:57
1
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 '13 at 5:23
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
add a comment |
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.
add a comment |
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.
add a comment |
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.
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.
answered Jan 7 at 0:51
Francisco LuzFrancisco Luz
1011
1011
add a comment |
add a comment |
Thanks for contributing an answer to Ask Ubuntu!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f318777%2fcombine-multiple-text-files-into-one-file%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown