How to concatenate several text files with a blank line in-between each? [duplicate]
Clash Royale CLAN TAG#URR8PPP
up vote
0
down vote
favorite
This question already has an answer here:
Concatenate multiple files with two blank lines as delimiter?
6 answers
I am writing a shell script, and in that I am using three html files. Now I am trying to concatenate all three files, and send the content as an email to my self.
Please see below what I am trying to do
three file: hello.html
, hello1.html
, hello2.html
.
Now I am appending the output of all these three files to file Final.Html
file like below and sending it, as an email.
>Final.html
cat hello.html >> Final.html
cat hello1.html >> Final.html
cat hello2.html >> Final.html
cat Final.html | sendmail -t
Now my input of all three files is shown below
$ cat hello.html
Hello world
$ cat hello1.html
india is my world
$ cat hello2.html
India is the best
After sending the mail, the output I am getting is below
Hello world
india is my world
India is the best
The output I am looking for is below with one empty line between each file. To get a clean and clear output. Can anyone please help me on this?
Hello world
india is my world
India is the best
scripting
New contributor
marked as duplicate by don_crissti, RalfFriedl, Jeff Schaller, Goro, Thomas Oct 3 at 9:40
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |Â
up vote
0
down vote
favorite
This question already has an answer here:
Concatenate multiple files with two blank lines as delimiter?
6 answers
I am writing a shell script, and in that I am using three html files. Now I am trying to concatenate all three files, and send the content as an email to my self.
Please see below what I am trying to do
three file: hello.html
, hello1.html
, hello2.html
.
Now I am appending the output of all these three files to file Final.Html
file like below and sending it, as an email.
>Final.html
cat hello.html >> Final.html
cat hello1.html >> Final.html
cat hello2.html >> Final.html
cat Final.html | sendmail -t
Now my input of all three files is shown below
$ cat hello.html
Hello world
$ cat hello1.html
india is my world
$ cat hello2.html
India is the best
After sending the mail, the output I am getting is below
Hello world
india is my world
India is the best
The output I am looking for is below with one empty line between each file. To get a clean and clear output. Can anyone please help me on this?
Hello world
india is my world
India is the best
scripting
New contributor
marked as duplicate by don_crissti, RalfFriedl, Jeff Schaller, Goro, Thomas Oct 3 at 9:40
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
I think Brian may have been referring to the term âÂÂo/pâ as an abbreviation for âÂÂoutputâÂÂ. I agree that âÂÂoutputâ is more quickly understood. If these are really HTML files, do you need a<br>
or similar HTML code, versus a blank line?
â Jeff Schaller
Oct 1 at 20:47
add a comment |Â
up vote
0
down vote
favorite
up vote
0
down vote
favorite
This question already has an answer here:
Concatenate multiple files with two blank lines as delimiter?
6 answers
I am writing a shell script, and in that I am using three html files. Now I am trying to concatenate all three files, and send the content as an email to my self.
Please see below what I am trying to do
three file: hello.html
, hello1.html
, hello2.html
.
Now I am appending the output of all these three files to file Final.Html
file like below and sending it, as an email.
>Final.html
cat hello.html >> Final.html
cat hello1.html >> Final.html
cat hello2.html >> Final.html
cat Final.html | sendmail -t
Now my input of all three files is shown below
$ cat hello.html
Hello world
$ cat hello1.html
india is my world
$ cat hello2.html
India is the best
After sending the mail, the output I am getting is below
Hello world
india is my world
India is the best
The output I am looking for is below with one empty line between each file. To get a clean and clear output. Can anyone please help me on this?
Hello world
india is my world
India is the best
scripting
New contributor
This question already has an answer here:
Concatenate multiple files with two blank lines as delimiter?
6 answers
I am writing a shell script, and in that I am using three html files. Now I am trying to concatenate all three files, and send the content as an email to my self.
Please see below what I am trying to do
three file: hello.html
, hello1.html
, hello2.html
.
Now I am appending the output of all these three files to file Final.Html
file like below and sending it, as an email.
>Final.html
cat hello.html >> Final.html
cat hello1.html >> Final.html
cat hello2.html >> Final.html
cat Final.html | sendmail -t
Now my input of all three files is shown below
$ cat hello.html
Hello world
$ cat hello1.html
india is my world
$ cat hello2.html
India is the best
After sending the mail, the output I am getting is below
Hello world
india is my world
India is the best
The output I am looking for is below with one empty line between each file. To get a clean and clear output. Can anyone please help me on this?
Hello world
india is my world
India is the best
This question already has an answer here:
Concatenate multiple files with two blank lines as delimiter?
6 answers
scripting
scripting
New contributor
New contributor
edited Oct 2 at 11:48
Kusalananda
108k14210333
108k14210333
New contributor
asked Oct 1 at 17:02
Nikhil
111
111
New contributor
New contributor
marked as duplicate by don_crissti, RalfFriedl, Jeff Schaller, Goro, Thomas Oct 3 at 9:40
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
marked as duplicate by don_crissti, RalfFriedl, Jeff Schaller, Goro, Thomas Oct 3 at 9:40
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
I think Brian may have been referring to the term âÂÂo/pâ as an abbreviation for âÂÂoutputâÂÂ. I agree that âÂÂoutputâ is more quickly understood. If these are really HTML files, do you need a<br>
or similar HTML code, versus a blank line?
â Jeff Schaller
Oct 1 at 20:47
add a comment |Â
I think Brian may have been referring to the term âÂÂo/pâ as an abbreviation for âÂÂoutputâÂÂ. I agree that âÂÂoutputâ is more quickly understood. If these are really HTML files, do you need a<br>
or similar HTML code, versus a blank line?
â Jeff Schaller
Oct 1 at 20:47
I think Brian may have been referring to the term âÂÂo/pâ as an abbreviation for âÂÂoutputâÂÂ. I agree that âÂÂoutputâ is more quickly understood. If these are really HTML files, do you need a
<br>
or similar HTML code, versus a blank line?â Jeff Schaller
Oct 1 at 20:47
I think Brian may have been referring to the term âÂÂo/pâ as an abbreviation for âÂÂoutputâÂÂ. I agree that âÂÂoutputâ is more quickly understood. If these are really HTML files, do you need a
<br>
or similar HTML code, versus a blank line?â Jeff Schaller
Oct 1 at 20:47
add a comment |Â
4 Answers
4
active
oldest
votes
up vote
1
down vote
This should give the required output,
awk 'NR>1 && FNR==1print "";1' ./*.html > /path/to/Final.html
(make sure the output file is not in the list of input files)
New contributor
1
This is a neat solution, but it would be an even better answer if it had some description of what it is actually doing.
â Kusalananda
Oct 2 at 11:33
It will merge the contents of all files ending with .html by adding a new line after the contents of each file to Final.html
â Kamil Khan
Oct 2 at 11:36
add a comment |Â
up vote
0
down vote
You can do that all with one use of cat
which, while it is often used to display the contents of a file on the terminal, is actually made for con- cat -enating files (i. e. attaching them together):
$ cat hello.html hello1.html hello2.html | mail -s "Subject Goes Here" myself@mailhost.example.com
Thanks, but will that really work, will cat command not take only 1 filename as a file and others as an argument?, I need a space between each file merge so that the final content shall have three different line with a space between the , i will be more than happy to check your way out as well.
â Nikhil
Oct 1 at 17:26
This will do the same as original in question, it will not add the blank lines.
â ctrl-alt-delor
Oct 1 at 17:31
Thanks much for your time,will try and update
â Nikhil
Oct 1 at 17:37
add a comment |Â
up vote
0
down vote
This will do it, I have added code to add the blank lines.echo
will output a newline, it can also be used to output more.
>Final.html
cat hello.html >> Final.html
echo >> Final.html
cat hello1.html >> Final.html
echo >> Final.html
cat hello2.html >> Final.html
This next one uses a bracket, to reduce the amount of code.
cat hello.html
echo
cat hello1.html
echo
cat hello2.html
> Final.html
Since i am writing in Linux text while, I shall be using echo as well right before all the lines you have mentioned?
â Nikhil
Oct 1 at 17:39
Both of my examples (above), should produce exactly the same output. However the 2nd has repeated code, so is nicer. (it only has> Final.html
once)
â ctrl-alt-delor
Oct 1 at 17:41
1
Thank you so much
â Nikhil
Oct 1 at 17:43
add a comment |Â
up vote
0
down vote
Using GNU awk
(which supports the ENDFILE
special pattern):
awk '1; ENDFILE print "" ' hello.html hello1.html hello2.html >Final.html
The awk
script passes the data unmodified data of each file in turn (the 1;
may be replaced by print
, which does the same thing). At the end of each file, the ENDFILE
block will output an empty line.
To additionally insert the name of the file before the data of each file (this was not part of the question):
awk 'BEGINFILE print FILENAME 1
ENDFILE print "" ' hello.html hello1.html hello2.html >Final.html
The special pattern BEGINFILE
works just like ENDFILE
but will be triggered before reading the first line of a new file. The FILENAME
variable is a standard awk
variable and contains the pathname of the current input file.
add a comment |Â
4 Answers
4
active
oldest
votes
4 Answers
4
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
This should give the required output,
awk 'NR>1 && FNR==1print "";1' ./*.html > /path/to/Final.html
(make sure the output file is not in the list of input files)
New contributor
1
This is a neat solution, but it would be an even better answer if it had some description of what it is actually doing.
â Kusalananda
Oct 2 at 11:33
It will merge the contents of all files ending with .html by adding a new line after the contents of each file to Final.html
â Kamil Khan
Oct 2 at 11:36
add a comment |Â
up vote
1
down vote
This should give the required output,
awk 'NR>1 && FNR==1print "";1' ./*.html > /path/to/Final.html
(make sure the output file is not in the list of input files)
New contributor
1
This is a neat solution, but it would be an even better answer if it had some description of what it is actually doing.
â Kusalananda
Oct 2 at 11:33
It will merge the contents of all files ending with .html by adding a new line after the contents of each file to Final.html
â Kamil Khan
Oct 2 at 11:36
add a comment |Â
up vote
1
down vote
up vote
1
down vote
This should give the required output,
awk 'NR>1 && FNR==1print "";1' ./*.html > /path/to/Final.html
(make sure the output file is not in the list of input files)
New contributor
This should give the required output,
awk 'NR>1 && FNR==1print "";1' ./*.html > /path/to/Final.html
(make sure the output file is not in the list of input files)
New contributor
edited Oct 2 at 11:48
Stéphane Chazelas
287k53530867
287k53530867
New contributor
answered Oct 2 at 11:32
Kamil Khan
111
111
New contributor
New contributor
1
This is a neat solution, but it would be an even better answer if it had some description of what it is actually doing.
â Kusalananda
Oct 2 at 11:33
It will merge the contents of all files ending with .html by adding a new line after the contents of each file to Final.html
â Kamil Khan
Oct 2 at 11:36
add a comment |Â
1
This is a neat solution, but it would be an even better answer if it had some description of what it is actually doing.
â Kusalananda
Oct 2 at 11:33
It will merge the contents of all files ending with .html by adding a new line after the contents of each file to Final.html
â Kamil Khan
Oct 2 at 11:36
1
1
This is a neat solution, but it would be an even better answer if it had some description of what it is actually doing.
â Kusalananda
Oct 2 at 11:33
This is a neat solution, but it would be an even better answer if it had some description of what it is actually doing.
â Kusalananda
Oct 2 at 11:33
It will merge the contents of all files ending with .html by adding a new line after the contents of each file to Final.html
â Kamil Khan
Oct 2 at 11:36
It will merge the contents of all files ending with .html by adding a new line after the contents of each file to Final.html
â Kamil Khan
Oct 2 at 11:36
add a comment |Â
up vote
0
down vote
You can do that all with one use of cat
which, while it is often used to display the contents of a file on the terminal, is actually made for con- cat -enating files (i. e. attaching them together):
$ cat hello.html hello1.html hello2.html | mail -s "Subject Goes Here" myself@mailhost.example.com
Thanks, but will that really work, will cat command not take only 1 filename as a file and others as an argument?, I need a space between each file merge so that the final content shall have three different line with a space between the , i will be more than happy to check your way out as well.
â Nikhil
Oct 1 at 17:26
This will do the same as original in question, it will not add the blank lines.
â ctrl-alt-delor
Oct 1 at 17:31
Thanks much for your time,will try and update
â Nikhil
Oct 1 at 17:37
add a comment |Â
up vote
0
down vote
You can do that all with one use of cat
which, while it is often used to display the contents of a file on the terminal, is actually made for con- cat -enating files (i. e. attaching them together):
$ cat hello.html hello1.html hello2.html | mail -s "Subject Goes Here" myself@mailhost.example.com
Thanks, but will that really work, will cat command not take only 1 filename as a file and others as an argument?, I need a space between each file merge so that the final content shall have three different line with a space between the , i will be more than happy to check your way out as well.
â Nikhil
Oct 1 at 17:26
This will do the same as original in question, it will not add the blank lines.
â ctrl-alt-delor
Oct 1 at 17:31
Thanks much for your time,will try and update
â Nikhil
Oct 1 at 17:37
add a comment |Â
up vote
0
down vote
up vote
0
down vote
You can do that all with one use of cat
which, while it is often used to display the contents of a file on the terminal, is actually made for con- cat -enating files (i. e. attaching them together):
$ cat hello.html hello1.html hello2.html | mail -s "Subject Goes Here" myself@mailhost.example.com
You can do that all with one use of cat
which, while it is often used to display the contents of a file on the terminal, is actually made for con- cat -enating files (i. e. attaching them together):
$ cat hello.html hello1.html hello2.html | mail -s "Subject Goes Here" myself@mailhost.example.com
answered Oct 1 at 17:13
DopeGhoti
41.5k55180
41.5k55180
Thanks, but will that really work, will cat command not take only 1 filename as a file and others as an argument?, I need a space between each file merge so that the final content shall have three different line with a space between the , i will be more than happy to check your way out as well.
â Nikhil
Oct 1 at 17:26
This will do the same as original in question, it will not add the blank lines.
â ctrl-alt-delor
Oct 1 at 17:31
Thanks much for your time,will try and update
â Nikhil
Oct 1 at 17:37
add a comment |Â
Thanks, but will that really work, will cat command not take only 1 filename as a file and others as an argument?, I need a space between each file merge so that the final content shall have three different line with a space between the , i will be more than happy to check your way out as well.
â Nikhil
Oct 1 at 17:26
This will do the same as original in question, it will not add the blank lines.
â ctrl-alt-delor
Oct 1 at 17:31
Thanks much for your time,will try and update
â Nikhil
Oct 1 at 17:37
Thanks, but will that really work, will cat command not take only 1 filename as a file and others as an argument?, I need a space between each file merge so that the final content shall have three different line with a space between the , i will be more than happy to check your way out as well.
â Nikhil
Oct 1 at 17:26
Thanks, but will that really work, will cat command not take only 1 filename as a file and others as an argument?, I need a space between each file merge so that the final content shall have three different line with a space between the , i will be more than happy to check your way out as well.
â Nikhil
Oct 1 at 17:26
This will do the same as original in question, it will not add the blank lines.
â ctrl-alt-delor
Oct 1 at 17:31
This will do the same as original in question, it will not add the blank lines.
â ctrl-alt-delor
Oct 1 at 17:31
Thanks much for your time,will try and update
â Nikhil
Oct 1 at 17:37
Thanks much for your time,will try and update
â Nikhil
Oct 1 at 17:37
add a comment |Â
up vote
0
down vote
This will do it, I have added code to add the blank lines.echo
will output a newline, it can also be used to output more.
>Final.html
cat hello.html >> Final.html
echo >> Final.html
cat hello1.html >> Final.html
echo >> Final.html
cat hello2.html >> Final.html
This next one uses a bracket, to reduce the amount of code.
cat hello.html
echo
cat hello1.html
echo
cat hello2.html
> Final.html
Since i am writing in Linux text while, I shall be using echo as well right before all the lines you have mentioned?
â Nikhil
Oct 1 at 17:39
Both of my examples (above), should produce exactly the same output. However the 2nd has repeated code, so is nicer. (it only has> Final.html
once)
â ctrl-alt-delor
Oct 1 at 17:41
1
Thank you so much
â Nikhil
Oct 1 at 17:43
add a comment |Â
up vote
0
down vote
This will do it, I have added code to add the blank lines.echo
will output a newline, it can also be used to output more.
>Final.html
cat hello.html >> Final.html
echo >> Final.html
cat hello1.html >> Final.html
echo >> Final.html
cat hello2.html >> Final.html
This next one uses a bracket, to reduce the amount of code.
cat hello.html
echo
cat hello1.html
echo
cat hello2.html
> Final.html
Since i am writing in Linux text while, I shall be using echo as well right before all the lines you have mentioned?
â Nikhil
Oct 1 at 17:39
Both of my examples (above), should produce exactly the same output. However the 2nd has repeated code, so is nicer. (it only has> Final.html
once)
â ctrl-alt-delor
Oct 1 at 17:41
1
Thank you so much
â Nikhil
Oct 1 at 17:43
add a comment |Â
up vote
0
down vote
up vote
0
down vote
This will do it, I have added code to add the blank lines.echo
will output a newline, it can also be used to output more.
>Final.html
cat hello.html >> Final.html
echo >> Final.html
cat hello1.html >> Final.html
echo >> Final.html
cat hello2.html >> Final.html
This next one uses a bracket, to reduce the amount of code.
cat hello.html
echo
cat hello1.html
echo
cat hello2.html
> Final.html
This will do it, I have added code to add the blank lines.echo
will output a newline, it can also be used to output more.
>Final.html
cat hello.html >> Final.html
echo >> Final.html
cat hello1.html >> Final.html
echo >> Final.html
cat hello2.html >> Final.html
This next one uses a bracket, to reduce the amount of code.
cat hello.html
echo
cat hello1.html
echo
cat hello2.html
> Final.html
answered Oct 1 at 17:31
ctrl-alt-delor
9,23831948
9,23831948
Since i am writing in Linux text while, I shall be using echo as well right before all the lines you have mentioned?
â Nikhil
Oct 1 at 17:39
Both of my examples (above), should produce exactly the same output. However the 2nd has repeated code, so is nicer. (it only has> Final.html
once)
â ctrl-alt-delor
Oct 1 at 17:41
1
Thank you so much
â Nikhil
Oct 1 at 17:43
add a comment |Â
Since i am writing in Linux text while, I shall be using echo as well right before all the lines you have mentioned?
â Nikhil
Oct 1 at 17:39
Both of my examples (above), should produce exactly the same output. However the 2nd has repeated code, so is nicer. (it only has> Final.html
once)
â ctrl-alt-delor
Oct 1 at 17:41
1
Thank you so much
â Nikhil
Oct 1 at 17:43
Since i am writing in Linux text while, I shall be using echo as well right before all the lines you have mentioned?
â Nikhil
Oct 1 at 17:39
Since i am writing in Linux text while, I shall be using echo as well right before all the lines you have mentioned?
â Nikhil
Oct 1 at 17:39
Both of my examples (above), should produce exactly the same output. However the 2nd has repeated code, so is nicer. (it only has
> Final.html
once)â ctrl-alt-delor
Oct 1 at 17:41
Both of my examples (above), should produce exactly the same output. However the 2nd has repeated code, so is nicer. (it only has
> Final.html
once)â ctrl-alt-delor
Oct 1 at 17:41
1
1
Thank you so much
â Nikhil
Oct 1 at 17:43
Thank you so much
â Nikhil
Oct 1 at 17:43
add a comment |Â
up vote
0
down vote
Using GNU awk
(which supports the ENDFILE
special pattern):
awk '1; ENDFILE print "" ' hello.html hello1.html hello2.html >Final.html
The awk
script passes the data unmodified data of each file in turn (the 1;
may be replaced by print
, which does the same thing). At the end of each file, the ENDFILE
block will output an empty line.
To additionally insert the name of the file before the data of each file (this was not part of the question):
awk 'BEGINFILE print FILENAME 1
ENDFILE print "" ' hello.html hello1.html hello2.html >Final.html
The special pattern BEGINFILE
works just like ENDFILE
but will be triggered before reading the first line of a new file. The FILENAME
variable is a standard awk
variable and contains the pathname of the current input file.
add a comment |Â
up vote
0
down vote
Using GNU awk
(which supports the ENDFILE
special pattern):
awk '1; ENDFILE print "" ' hello.html hello1.html hello2.html >Final.html
The awk
script passes the data unmodified data of each file in turn (the 1;
may be replaced by print
, which does the same thing). At the end of each file, the ENDFILE
block will output an empty line.
To additionally insert the name of the file before the data of each file (this was not part of the question):
awk 'BEGINFILE print FILENAME 1
ENDFILE print "" ' hello.html hello1.html hello2.html >Final.html
The special pattern BEGINFILE
works just like ENDFILE
but will be triggered before reading the first line of a new file. The FILENAME
variable is a standard awk
variable and contains the pathname of the current input file.
add a comment |Â
up vote
0
down vote
up vote
0
down vote
Using GNU awk
(which supports the ENDFILE
special pattern):
awk '1; ENDFILE print "" ' hello.html hello1.html hello2.html >Final.html
The awk
script passes the data unmodified data of each file in turn (the 1;
may be replaced by print
, which does the same thing). At the end of each file, the ENDFILE
block will output an empty line.
To additionally insert the name of the file before the data of each file (this was not part of the question):
awk 'BEGINFILE print FILENAME 1
ENDFILE print "" ' hello.html hello1.html hello2.html >Final.html
The special pattern BEGINFILE
works just like ENDFILE
but will be triggered before reading the first line of a new file. The FILENAME
variable is a standard awk
variable and contains the pathname of the current input file.
Using GNU awk
(which supports the ENDFILE
special pattern):
awk '1; ENDFILE print "" ' hello.html hello1.html hello2.html >Final.html
The awk
script passes the data unmodified data of each file in turn (the 1;
may be replaced by print
, which does the same thing). At the end of each file, the ENDFILE
block will output an empty line.
To additionally insert the name of the file before the data of each file (this was not part of the question):
awk 'BEGINFILE print FILENAME 1
ENDFILE print "" ' hello.html hello1.html hello2.html >Final.html
The special pattern BEGINFILE
works just like ENDFILE
but will be triggered before reading the first line of a new file. The FILENAME
variable is a standard awk
variable and contains the pathname of the current input file.
edited Oct 2 at 11:50
answered Oct 2 at 11:42
Kusalananda
108k14210333
108k14210333
add a comment |Â
add a comment |Â
I think Brian may have been referring to the term âÂÂo/pâ as an abbreviation for âÂÂoutputâÂÂ. I agree that âÂÂoutputâ is more quickly understood. If these are really HTML files, do you need a
<br>
or similar HTML code, versus a blank line?â Jeff Schaller
Oct 1 at 20:47