Merge text files next to each other
![Creative The name of the picture](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgO9GURib1T8z7lCwjOGLQaGtrueEthgQ8LO42ZX8cOfTqDK4jvDDpKkLFwf2J49kYCMNW7d4ABih_XCb_2UXdq5fPJDkoyg7-8g_YfRUot-XnaXkNYycsNp7lA5_TW9td0FFpLQ2APzKcZ/s1600/1.jpg)
![Creative The name of the picture](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhYQ0N5W1qAOxLP7t7iOM6O6AzbZnkXUy16s7P_CWfOb5UbTQY_aDsc727chyphenhyphen5W4IppVNernMMQeaUFTB_rFzAd95_CDt-tnwN-nBx6JyUp2duGjPaL5-VgNO41AVsA_vu30EJcipdDG409/s400/Clash+Royale+CLAN+TAG%2523URR8PPP.png)
up vote
1
down vote
favorite
I have .txt
data from spectrometer with 800 lines and 5 columns. And I want to merge about 15 these files next to each other. So final .txt
file should have 800 lines and 75 columns.
All .txt
files looks like this:
Wave ;Sample ;Dark ;Reference;Absorbance
[nm] ;[counts] ;[counts] ;[counts] ;[A.U]
200.00; 34.647; -0.317; 79.668; 0.35734
201.00; 29.937; -21.220; 70.385; 0.25357
202.00; 48.826; -0.527; 99.657; 0.30721
203.00; 43.201; 4.165; 136.775; 0.53103
...
Desired file:
Wave ;Sample ;Dark ;Reference;Absorbance; Wave ;Sample ;Dark ;Reference;Absorbance
[nm] ;[counts] ;[counts] ;[counts] ;[A.U]; [nm] ;[counts] ;[counts] ;[counts] ;[A.U]
200.00; 34.647; -0.317; 79.668; 0.35734; 200.00; 34.647; -0.317; 79.668; 0.35734;
201.00; 29.937; -21.220; 70.385; 0.25357; 201.00; 29.937; -21.220; 70.385; 0.25357
202.00; 48.826; -0.527; 99.657; 0.30721; 202.00; 48.826; -0.527; 99.657; 0.30721
203.00; 43.201; 4.165; 136.775; 0.53103; 203.00; 43.201; 4.165; 136.775; 0.53103
I tried:
cat *.txt > file.txt
But this add .txt
files like new lines not like new columns.
command-line text-processing
add a comment |Â
up vote
1
down vote
favorite
I have .txt
data from spectrometer with 800 lines and 5 columns. And I want to merge about 15 these files next to each other. So final .txt
file should have 800 lines and 75 columns.
All .txt
files looks like this:
Wave ;Sample ;Dark ;Reference;Absorbance
[nm] ;[counts] ;[counts] ;[counts] ;[A.U]
200.00; 34.647; -0.317; 79.668; 0.35734
201.00; 29.937; -21.220; 70.385; 0.25357
202.00; 48.826; -0.527; 99.657; 0.30721
203.00; 43.201; 4.165; 136.775; 0.53103
...
Desired file:
Wave ;Sample ;Dark ;Reference;Absorbance; Wave ;Sample ;Dark ;Reference;Absorbance
[nm] ;[counts] ;[counts] ;[counts] ;[A.U]; [nm] ;[counts] ;[counts] ;[counts] ;[A.U]
200.00; 34.647; -0.317; 79.668; 0.35734; 200.00; 34.647; -0.317; 79.668; 0.35734;
201.00; 29.937; -21.220; 70.385; 0.25357; 201.00; 29.937; -21.220; 70.385; 0.25357
202.00; 48.826; -0.527; 99.657; 0.30721; 202.00; 48.826; -0.527; 99.657; 0.30721
203.00; 43.201; 4.165; 136.775; 0.53103; 203.00; 43.201; 4.165; 136.775; 0.53103
I tried:
cat *.txt > file.txt
But this add .txt
files like new lines not like new columns.
command-line text-processing
2
Add some example input files and your desired output from those.
â heemayl
Mar 9 at 9:02
1
If you want to do it only once, you can do manually/visually in Libre Office Calc, by pasting the files into the spreadsheet.
â sudodus
Mar 9 at 9:31
add a comment |Â
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I have .txt
data from spectrometer with 800 lines and 5 columns. And I want to merge about 15 these files next to each other. So final .txt
file should have 800 lines and 75 columns.
All .txt
files looks like this:
Wave ;Sample ;Dark ;Reference;Absorbance
[nm] ;[counts] ;[counts] ;[counts] ;[A.U]
200.00; 34.647; -0.317; 79.668; 0.35734
201.00; 29.937; -21.220; 70.385; 0.25357
202.00; 48.826; -0.527; 99.657; 0.30721
203.00; 43.201; 4.165; 136.775; 0.53103
...
Desired file:
Wave ;Sample ;Dark ;Reference;Absorbance; Wave ;Sample ;Dark ;Reference;Absorbance
[nm] ;[counts] ;[counts] ;[counts] ;[A.U]; [nm] ;[counts] ;[counts] ;[counts] ;[A.U]
200.00; 34.647; -0.317; 79.668; 0.35734; 200.00; 34.647; -0.317; 79.668; 0.35734;
201.00; 29.937; -21.220; 70.385; 0.25357; 201.00; 29.937; -21.220; 70.385; 0.25357
202.00; 48.826; -0.527; 99.657; 0.30721; 202.00; 48.826; -0.527; 99.657; 0.30721
203.00; 43.201; 4.165; 136.775; 0.53103; 203.00; 43.201; 4.165; 136.775; 0.53103
I tried:
cat *.txt > file.txt
But this add .txt
files like new lines not like new columns.
command-line text-processing
I have .txt
data from spectrometer with 800 lines and 5 columns. And I want to merge about 15 these files next to each other. So final .txt
file should have 800 lines and 75 columns.
All .txt
files looks like this:
Wave ;Sample ;Dark ;Reference;Absorbance
[nm] ;[counts] ;[counts] ;[counts] ;[A.U]
200.00; 34.647; -0.317; 79.668; 0.35734
201.00; 29.937; -21.220; 70.385; 0.25357
202.00; 48.826; -0.527; 99.657; 0.30721
203.00; 43.201; 4.165; 136.775; 0.53103
...
Desired file:
Wave ;Sample ;Dark ;Reference;Absorbance; Wave ;Sample ;Dark ;Reference;Absorbance
[nm] ;[counts] ;[counts] ;[counts] ;[A.U]; [nm] ;[counts] ;[counts] ;[counts] ;[A.U]
200.00; 34.647; -0.317; 79.668; 0.35734; 200.00; 34.647; -0.317; 79.668; 0.35734;
201.00; 29.937; -21.220; 70.385; 0.25357; 201.00; 29.937; -21.220; 70.385; 0.25357
202.00; 48.826; -0.527; 99.657; 0.30721; 202.00; 48.826; -0.527; 99.657; 0.30721
203.00; 43.201; 4.165; 136.775; 0.53103; 203.00; 43.201; 4.165; 136.775; 0.53103
I tried:
cat *.txt > file.txt
But this add .txt
files like new lines not like new columns.
command-line text-processing
command-line text-processing
edited Mar 10 at 0:44
![](https://i.stack.imgur.com/ypy8w.png?s=32&g=1)
![](https://i.stack.imgur.com/ypy8w.png?s=32&g=1)
galoget
2,1062820
2,1062820
asked Mar 9 at 8:55
Adam Srut
83
83
2
Add some example input files and your desired output from those.
â heemayl
Mar 9 at 9:02
1
If you want to do it only once, you can do manually/visually in Libre Office Calc, by pasting the files into the spreadsheet.
â sudodus
Mar 9 at 9:31
add a comment |Â
2
Add some example input files and your desired output from those.
â heemayl
Mar 9 at 9:02
1
If you want to do it only once, you can do manually/visually in Libre Office Calc, by pasting the files into the spreadsheet.
â sudodus
Mar 9 at 9:31
2
2
Add some example input files and your desired output from those.
â heemayl
Mar 9 at 9:02
Add some example input files and your desired output from those.
â heemayl
Mar 9 at 9:02
1
1
If you want to do it only once, you can do manually/visually in Libre Office Calc, by pasting the files into the spreadsheet.
â sudodus
Mar 9 at 9:31
If you want to do it only once, you can do manually/visually in Libre Office Calc, by pasting the files into the spreadsheet.
â sudodus
Mar 9 at 9:31
add a comment |Â
2 Answers
2
active
oldest
votes
up vote
4
down vote
accepted
YouâÂÂre looking for the paste
utility, e.g.
paste *.txt > file.txt
Check its manual page for details, most notably the -d
option to specify the delimiter.
I'm probably looking for sdiff. But I don't know what option use. Each file should be delimited with ";" but there is "tab |".
â Adam Srut
Mar 9 at 10:15
@AdamSrut, Please explain with much more details, what you want! Edit your original question to add these details.
â sudodus
Mar 9 at 16:44
sorry sdiff works only on two files... I edited my question.
â Adam Srut
Mar 9 at 17:45
add a comment |Â
up vote
3
down vote
Simple example
I set the separator to 'space' and eliminate multiple spaces.
$ cat file-1
ett tu tre
1 2 3
11 22 33
$ cat file-2
fyra fem sex
4 5 6
44 55 66
$ cat file-3
sju atta nio
7 8 9
77 88 99
$ paste file-?
ett tu tre fyra fem sex sju atta nio
1 2 3 4 5 6 7 8 9
11 22 33 44 55 66 77 88 99
$ paste -d ' ' file-?
ett tu tre fyra fem sex sju atta nio
1 2 3 4 5 6 7 8 9
11 22 33 44 55 66 77 88 99
$ paste -d ' ' file-? | tr -s ' ' ' '
ett tu tre fyra fem sex sju atta nio
1 2 3 4 5 6 7 8 9
11 22 33 44 55 66 77 88 99
Suggested command line
Maybe you want to eliminate the spaces? You want to keep semicolon as separator. Try with the following command line
paste -d ';' input-filespec-with-wildcard | sed 's/ //g' > output-file
where input-filespec-with-wildcard
could be *.txt
(if the files to be merged are the only txt
files in the directory).
Edit (using the real data)
Convert the files to unix/linux text format,
CarriageReturn + LineFeed
-->LineFeed
withdos2unix
Remove blank lines with the following command
for i in *.TXT;do echo sed '/^$/'d "$i" > "$i/.TXT/.txt";done
Remove header lines with the following command
for i in *.txt;do grep ';*;' "$i" > "$i/.txt/.txt1";done
(Header lines do not contain at least two semicolons.)
Merge the files with the following command
paste -d ';' *.txt1 | sed 's/ //g' > merged-file.txt
I read the merged file into LibreOffice Calc and used semicolon as separator. It looks like I think you want to have it. I hope it works for you according to these instructions. Otherwise please describe your remaining problem and tell me if you want me to upload 'my' merged-file.txt
.
LibreOffice Calc
If you want to do it only once, you can do manually/visually in Libre Office Calc, by pasting the files into the spreadsheet. You can edit the positions in the spreadsheet and remove the lines, that create confusion.
I would say that it is rather easy to do it manually in LibreOffice Calc, but if this is something that you will do many times or with a great number of files, it is better to use and maybe refine the command line method.
That is almost it! But I get line from each file under line from previous file as a result. So I tried to eliminate end of lines "n" and I type | sed 's/n//g' but that does not work.
â Adam Srut
Mar 12 at 21:38
You can trytr 'n' ';'
to convert the unwanted newlines to semicolons (which you use as separators). But it will remove all newlines, and that is probably not what you want. If you have blank lines (two newlines next to each other), you can trysed '/^$/'d
where ^ marks the beginning of a line and $ marks the end of a line and d tells sed to delete the line (the blank line).
â sudodus
Mar 13 at 7:06
But I am guessing. You can make it easier to help, if you upload some of the real files, that you want to merge and post a link to them. Then I can develop a method, that works for the real case. (If the files are secret, I can give you my public key for gpg encryption so that you can make them readable only for me.)
â sudodus
Mar 13 at 7:12
Yes I understand. Here is link to the files <vscht-my.sharepoint.com/:f:/g/personal/sruta_vscht_cz/â¦;
â Adam Srut
Mar 13 at 8:33
@AdamSrut, Have a look at what I think is a working solution.
â sudodus
Mar 13 at 11:02
add a comment |Â
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
4
down vote
accepted
YouâÂÂre looking for the paste
utility, e.g.
paste *.txt > file.txt
Check its manual page for details, most notably the -d
option to specify the delimiter.
I'm probably looking for sdiff. But I don't know what option use. Each file should be delimited with ";" but there is "tab |".
â Adam Srut
Mar 9 at 10:15
@AdamSrut, Please explain with much more details, what you want! Edit your original question to add these details.
â sudodus
Mar 9 at 16:44
sorry sdiff works only on two files... I edited my question.
â Adam Srut
Mar 9 at 17:45
add a comment |Â
up vote
4
down vote
accepted
YouâÂÂre looking for the paste
utility, e.g.
paste *.txt > file.txt
Check its manual page for details, most notably the -d
option to specify the delimiter.
I'm probably looking for sdiff. But I don't know what option use. Each file should be delimited with ";" but there is "tab |".
â Adam Srut
Mar 9 at 10:15
@AdamSrut, Please explain with much more details, what you want! Edit your original question to add these details.
â sudodus
Mar 9 at 16:44
sorry sdiff works only on two files... I edited my question.
â Adam Srut
Mar 9 at 17:45
add a comment |Â
up vote
4
down vote
accepted
up vote
4
down vote
accepted
YouâÂÂre looking for the paste
utility, e.g.
paste *.txt > file.txt
Check its manual page for details, most notably the -d
option to specify the delimiter.
YouâÂÂre looking for the paste
utility, e.g.
paste *.txt > file.txt
Check its manual page for details, most notably the -d
option to specify the delimiter.
answered Mar 9 at 9:42
egmont
3,5691821
3,5691821
I'm probably looking for sdiff. But I don't know what option use. Each file should be delimited with ";" but there is "tab |".
â Adam Srut
Mar 9 at 10:15
@AdamSrut, Please explain with much more details, what you want! Edit your original question to add these details.
â sudodus
Mar 9 at 16:44
sorry sdiff works only on two files... I edited my question.
â Adam Srut
Mar 9 at 17:45
add a comment |Â
I'm probably looking for sdiff. But I don't know what option use. Each file should be delimited with ";" but there is "tab |".
â Adam Srut
Mar 9 at 10:15
@AdamSrut, Please explain with much more details, what you want! Edit your original question to add these details.
â sudodus
Mar 9 at 16:44
sorry sdiff works only on two files... I edited my question.
â Adam Srut
Mar 9 at 17:45
I'm probably looking for sdiff. But I don't know what option use. Each file should be delimited with ";" but there is "tab |".
â Adam Srut
Mar 9 at 10:15
I'm probably looking for sdiff. But I don't know what option use. Each file should be delimited with ";" but there is "tab |".
â Adam Srut
Mar 9 at 10:15
@AdamSrut, Please explain with much more details, what you want! Edit your original question to add these details.
â sudodus
Mar 9 at 16:44
@AdamSrut, Please explain with much more details, what you want! Edit your original question to add these details.
â sudodus
Mar 9 at 16:44
sorry sdiff works only on two files... I edited my question.
â Adam Srut
Mar 9 at 17:45
sorry sdiff works only on two files... I edited my question.
â Adam Srut
Mar 9 at 17:45
add a comment |Â
up vote
3
down vote
Simple example
I set the separator to 'space' and eliminate multiple spaces.
$ cat file-1
ett tu tre
1 2 3
11 22 33
$ cat file-2
fyra fem sex
4 5 6
44 55 66
$ cat file-3
sju atta nio
7 8 9
77 88 99
$ paste file-?
ett tu tre fyra fem sex sju atta nio
1 2 3 4 5 6 7 8 9
11 22 33 44 55 66 77 88 99
$ paste -d ' ' file-?
ett tu tre fyra fem sex sju atta nio
1 2 3 4 5 6 7 8 9
11 22 33 44 55 66 77 88 99
$ paste -d ' ' file-? | tr -s ' ' ' '
ett tu tre fyra fem sex sju atta nio
1 2 3 4 5 6 7 8 9
11 22 33 44 55 66 77 88 99
Suggested command line
Maybe you want to eliminate the spaces? You want to keep semicolon as separator. Try with the following command line
paste -d ';' input-filespec-with-wildcard | sed 's/ //g' > output-file
where input-filespec-with-wildcard
could be *.txt
(if the files to be merged are the only txt
files in the directory).
Edit (using the real data)
Convert the files to unix/linux text format,
CarriageReturn + LineFeed
-->LineFeed
withdos2unix
Remove blank lines with the following command
for i in *.TXT;do echo sed '/^$/'d "$i" > "$i/.TXT/.txt";done
Remove header lines with the following command
for i in *.txt;do grep ';*;' "$i" > "$i/.txt/.txt1";done
(Header lines do not contain at least two semicolons.)
Merge the files with the following command
paste -d ';' *.txt1 | sed 's/ //g' > merged-file.txt
I read the merged file into LibreOffice Calc and used semicolon as separator. It looks like I think you want to have it. I hope it works for you according to these instructions. Otherwise please describe your remaining problem and tell me if you want me to upload 'my' merged-file.txt
.
LibreOffice Calc
If you want to do it only once, you can do manually/visually in Libre Office Calc, by pasting the files into the spreadsheet. You can edit the positions in the spreadsheet and remove the lines, that create confusion.
I would say that it is rather easy to do it manually in LibreOffice Calc, but if this is something that you will do many times or with a great number of files, it is better to use and maybe refine the command line method.
That is almost it! But I get line from each file under line from previous file as a result. So I tried to eliminate end of lines "n" and I type | sed 's/n//g' but that does not work.
â Adam Srut
Mar 12 at 21:38
You can trytr 'n' ';'
to convert the unwanted newlines to semicolons (which you use as separators). But it will remove all newlines, and that is probably not what you want. If you have blank lines (two newlines next to each other), you can trysed '/^$/'d
where ^ marks the beginning of a line and $ marks the end of a line and d tells sed to delete the line (the blank line).
â sudodus
Mar 13 at 7:06
But I am guessing. You can make it easier to help, if you upload some of the real files, that you want to merge and post a link to them. Then I can develop a method, that works for the real case. (If the files are secret, I can give you my public key for gpg encryption so that you can make them readable only for me.)
â sudodus
Mar 13 at 7:12
Yes I understand. Here is link to the files <vscht-my.sharepoint.com/:f:/g/personal/sruta_vscht_cz/â¦;
â Adam Srut
Mar 13 at 8:33
@AdamSrut, Have a look at what I think is a working solution.
â sudodus
Mar 13 at 11:02
add a comment |Â
up vote
3
down vote
Simple example
I set the separator to 'space' and eliminate multiple spaces.
$ cat file-1
ett tu tre
1 2 3
11 22 33
$ cat file-2
fyra fem sex
4 5 6
44 55 66
$ cat file-3
sju atta nio
7 8 9
77 88 99
$ paste file-?
ett tu tre fyra fem sex sju atta nio
1 2 3 4 5 6 7 8 9
11 22 33 44 55 66 77 88 99
$ paste -d ' ' file-?
ett tu tre fyra fem sex sju atta nio
1 2 3 4 5 6 7 8 9
11 22 33 44 55 66 77 88 99
$ paste -d ' ' file-? | tr -s ' ' ' '
ett tu tre fyra fem sex sju atta nio
1 2 3 4 5 6 7 8 9
11 22 33 44 55 66 77 88 99
Suggested command line
Maybe you want to eliminate the spaces? You want to keep semicolon as separator. Try with the following command line
paste -d ';' input-filespec-with-wildcard | sed 's/ //g' > output-file
where input-filespec-with-wildcard
could be *.txt
(if the files to be merged are the only txt
files in the directory).
Edit (using the real data)
Convert the files to unix/linux text format,
CarriageReturn + LineFeed
-->LineFeed
withdos2unix
Remove blank lines with the following command
for i in *.TXT;do echo sed '/^$/'d "$i" > "$i/.TXT/.txt";done
Remove header lines with the following command
for i in *.txt;do grep ';*;' "$i" > "$i/.txt/.txt1";done
(Header lines do not contain at least two semicolons.)
Merge the files with the following command
paste -d ';' *.txt1 | sed 's/ //g' > merged-file.txt
I read the merged file into LibreOffice Calc and used semicolon as separator. It looks like I think you want to have it. I hope it works for you according to these instructions. Otherwise please describe your remaining problem and tell me if you want me to upload 'my' merged-file.txt
.
LibreOffice Calc
If you want to do it only once, you can do manually/visually in Libre Office Calc, by pasting the files into the spreadsheet. You can edit the positions in the spreadsheet and remove the lines, that create confusion.
I would say that it is rather easy to do it manually in LibreOffice Calc, but if this is something that you will do many times or with a great number of files, it is better to use and maybe refine the command line method.
That is almost it! But I get line from each file under line from previous file as a result. So I tried to eliminate end of lines "n" and I type | sed 's/n//g' but that does not work.
â Adam Srut
Mar 12 at 21:38
You can trytr 'n' ';'
to convert the unwanted newlines to semicolons (which you use as separators). But it will remove all newlines, and that is probably not what you want. If you have blank lines (two newlines next to each other), you can trysed '/^$/'d
where ^ marks the beginning of a line and $ marks the end of a line and d tells sed to delete the line (the blank line).
â sudodus
Mar 13 at 7:06
But I am guessing. You can make it easier to help, if you upload some of the real files, that you want to merge and post a link to them. Then I can develop a method, that works for the real case. (If the files are secret, I can give you my public key for gpg encryption so that you can make them readable only for me.)
â sudodus
Mar 13 at 7:12
Yes I understand. Here is link to the files <vscht-my.sharepoint.com/:f:/g/personal/sruta_vscht_cz/â¦;
â Adam Srut
Mar 13 at 8:33
@AdamSrut, Have a look at what I think is a working solution.
â sudodus
Mar 13 at 11:02
add a comment |Â
up vote
3
down vote
up vote
3
down vote
Simple example
I set the separator to 'space' and eliminate multiple spaces.
$ cat file-1
ett tu tre
1 2 3
11 22 33
$ cat file-2
fyra fem sex
4 5 6
44 55 66
$ cat file-3
sju atta nio
7 8 9
77 88 99
$ paste file-?
ett tu tre fyra fem sex sju atta nio
1 2 3 4 5 6 7 8 9
11 22 33 44 55 66 77 88 99
$ paste -d ' ' file-?
ett tu tre fyra fem sex sju atta nio
1 2 3 4 5 6 7 8 9
11 22 33 44 55 66 77 88 99
$ paste -d ' ' file-? | tr -s ' ' ' '
ett tu tre fyra fem sex sju atta nio
1 2 3 4 5 6 7 8 9
11 22 33 44 55 66 77 88 99
Suggested command line
Maybe you want to eliminate the spaces? You want to keep semicolon as separator. Try with the following command line
paste -d ';' input-filespec-with-wildcard | sed 's/ //g' > output-file
where input-filespec-with-wildcard
could be *.txt
(if the files to be merged are the only txt
files in the directory).
Edit (using the real data)
Convert the files to unix/linux text format,
CarriageReturn + LineFeed
-->LineFeed
withdos2unix
Remove blank lines with the following command
for i in *.TXT;do echo sed '/^$/'d "$i" > "$i/.TXT/.txt";done
Remove header lines with the following command
for i in *.txt;do grep ';*;' "$i" > "$i/.txt/.txt1";done
(Header lines do not contain at least two semicolons.)
Merge the files with the following command
paste -d ';' *.txt1 | sed 's/ //g' > merged-file.txt
I read the merged file into LibreOffice Calc and used semicolon as separator. It looks like I think you want to have it. I hope it works for you according to these instructions. Otherwise please describe your remaining problem and tell me if you want me to upload 'my' merged-file.txt
.
LibreOffice Calc
If you want to do it only once, you can do manually/visually in Libre Office Calc, by pasting the files into the spreadsheet. You can edit the positions in the spreadsheet and remove the lines, that create confusion.
I would say that it is rather easy to do it manually in LibreOffice Calc, but if this is something that you will do many times or with a great number of files, it is better to use and maybe refine the command line method.
Simple example
I set the separator to 'space' and eliminate multiple spaces.
$ cat file-1
ett tu tre
1 2 3
11 22 33
$ cat file-2
fyra fem sex
4 5 6
44 55 66
$ cat file-3
sju atta nio
7 8 9
77 88 99
$ paste file-?
ett tu tre fyra fem sex sju atta nio
1 2 3 4 5 6 7 8 9
11 22 33 44 55 66 77 88 99
$ paste -d ' ' file-?
ett tu tre fyra fem sex sju atta nio
1 2 3 4 5 6 7 8 9
11 22 33 44 55 66 77 88 99
$ paste -d ' ' file-? | tr -s ' ' ' '
ett tu tre fyra fem sex sju atta nio
1 2 3 4 5 6 7 8 9
11 22 33 44 55 66 77 88 99
Suggested command line
Maybe you want to eliminate the spaces? You want to keep semicolon as separator. Try with the following command line
paste -d ';' input-filespec-with-wildcard | sed 's/ //g' > output-file
where input-filespec-with-wildcard
could be *.txt
(if the files to be merged are the only txt
files in the directory).
Edit (using the real data)
Convert the files to unix/linux text format,
CarriageReturn + LineFeed
-->LineFeed
withdos2unix
Remove blank lines with the following command
for i in *.TXT;do echo sed '/^$/'d "$i" > "$i/.TXT/.txt";done
Remove header lines with the following command
for i in *.txt;do grep ';*;' "$i" > "$i/.txt/.txt1";done
(Header lines do not contain at least two semicolons.)
Merge the files with the following command
paste -d ';' *.txt1 | sed 's/ //g' > merged-file.txt
I read the merged file into LibreOffice Calc and used semicolon as separator. It looks like I think you want to have it. I hope it works for you according to these instructions. Otherwise please describe your remaining problem and tell me if you want me to upload 'my' merged-file.txt
.
LibreOffice Calc
If you want to do it only once, you can do manually/visually in Libre Office Calc, by pasting the files into the spreadsheet. You can edit the positions in the spreadsheet and remove the lines, that create confusion.
I would say that it is rather easy to do it manually in LibreOffice Calc, but if this is something that you will do many times or with a great number of files, it is better to use and maybe refine the command line method.
edited Mar 13 at 11:00
answered Mar 9 at 18:17
![](https://i.stack.imgur.com/lcww5.png?s=32&g=1)
![](https://i.stack.imgur.com/lcww5.png?s=32&g=1)
sudodus
20.4k32668
20.4k32668
That is almost it! But I get line from each file under line from previous file as a result. So I tried to eliminate end of lines "n" and I type | sed 's/n//g' but that does not work.
â Adam Srut
Mar 12 at 21:38
You can trytr 'n' ';'
to convert the unwanted newlines to semicolons (which you use as separators). But it will remove all newlines, and that is probably not what you want. If you have blank lines (two newlines next to each other), you can trysed '/^$/'d
where ^ marks the beginning of a line and $ marks the end of a line and d tells sed to delete the line (the blank line).
â sudodus
Mar 13 at 7:06
But I am guessing. You can make it easier to help, if you upload some of the real files, that you want to merge and post a link to them. Then I can develop a method, that works for the real case. (If the files are secret, I can give you my public key for gpg encryption so that you can make them readable only for me.)
â sudodus
Mar 13 at 7:12
Yes I understand. Here is link to the files <vscht-my.sharepoint.com/:f:/g/personal/sruta_vscht_cz/â¦;
â Adam Srut
Mar 13 at 8:33
@AdamSrut, Have a look at what I think is a working solution.
â sudodus
Mar 13 at 11:02
add a comment |Â
That is almost it! But I get line from each file under line from previous file as a result. So I tried to eliminate end of lines "n" and I type | sed 's/n//g' but that does not work.
â Adam Srut
Mar 12 at 21:38
You can trytr 'n' ';'
to convert the unwanted newlines to semicolons (which you use as separators). But it will remove all newlines, and that is probably not what you want. If you have blank lines (two newlines next to each other), you can trysed '/^$/'d
where ^ marks the beginning of a line and $ marks the end of a line and d tells sed to delete the line (the blank line).
â sudodus
Mar 13 at 7:06
But I am guessing. You can make it easier to help, if you upload some of the real files, that you want to merge and post a link to them. Then I can develop a method, that works for the real case. (If the files are secret, I can give you my public key for gpg encryption so that you can make them readable only for me.)
â sudodus
Mar 13 at 7:12
Yes I understand. Here is link to the files <vscht-my.sharepoint.com/:f:/g/personal/sruta_vscht_cz/â¦;
â Adam Srut
Mar 13 at 8:33
@AdamSrut, Have a look at what I think is a working solution.
â sudodus
Mar 13 at 11:02
That is almost it! But I get line from each file under line from previous file as a result. So I tried to eliminate end of lines "n" and I type | sed 's/n//g' but that does not work.
â Adam Srut
Mar 12 at 21:38
That is almost it! But I get line from each file under line from previous file as a result. So I tried to eliminate end of lines "n" and I type | sed 's/n//g' but that does not work.
â Adam Srut
Mar 12 at 21:38
You can try
tr 'n' ';'
to convert the unwanted newlines to semicolons (which you use as separators). But it will remove all newlines, and that is probably not what you want. If you have blank lines (two newlines next to each other), you can try sed '/^$/'d
where ^ marks the beginning of a line and $ marks the end of a line and d tells sed to delete the line (the blank line).â sudodus
Mar 13 at 7:06
You can try
tr 'n' ';'
to convert the unwanted newlines to semicolons (which you use as separators). But it will remove all newlines, and that is probably not what you want. If you have blank lines (two newlines next to each other), you can try sed '/^$/'d
where ^ marks the beginning of a line and $ marks the end of a line and d tells sed to delete the line (the blank line).â sudodus
Mar 13 at 7:06
But I am guessing. You can make it easier to help, if you upload some of the real files, that you want to merge and post a link to them. Then I can develop a method, that works for the real case. (If the files are secret, I can give you my public key for gpg encryption so that you can make them readable only for me.)
â sudodus
Mar 13 at 7:12
But I am guessing. You can make it easier to help, if you upload some of the real files, that you want to merge and post a link to them. Then I can develop a method, that works for the real case. (If the files are secret, I can give you my public key for gpg encryption so that you can make them readable only for me.)
â sudodus
Mar 13 at 7:12
Yes I understand. Here is link to the files <vscht-my.sharepoint.com/:f:/g/personal/sruta_vscht_cz/â¦;
â Adam Srut
Mar 13 at 8:33
Yes I understand. Here is link to the files <vscht-my.sharepoint.com/:f:/g/personal/sruta_vscht_cz/â¦;
â Adam Srut
Mar 13 at 8:33
@AdamSrut, Have a look at what I think is a working solution.
â sudodus
Mar 13 at 11:02
@AdamSrut, Have a look at what I think is a working solution.
â sudodus
Mar 13 at 11:02
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1013344%2fmerge-text-files-next-to-each-other%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
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
2
Add some example input files and your desired output from those.
â heemayl
Mar 9 at 9:02
1
If you want to do it only once, you can do manually/visually in Libre Office Calc, by pasting the files into the spreadsheet.
â sudodus
Mar 9 at 9:31