Adam Majdi
Adam Majdi

Reputation: 107

Paste two files into one using Linux

I was trying to paste two files into one in Linux:

file1

1 101 0 0 0 -9
1 102 0 0 0 -9
1 103 0 0 0 -9
1 104 0 0 0 -9
1 105 0 0 0 -9
1 106 0 0 0 -9
1 107 0 0 0 -9
1 108 0 0 0 -9
1 109 0 0 0 -9
1 110 0 0 0 -9

file2:

2 2 1 3 1 3 3 3 1 3 1 1 1 3 1 2 1 2 1 3 1 3 1 2 1 
1 2 3 3 1 1 3 3 1 1 1 1 3 3 2 2 1 1 1 1 3 3 1 1 1 
2 2 1 3 3 3 1 3 1 3 1 3 1 3 1 2 1 2 1 3 1 3 1 2 1 
1 2 3 3 3 3 1 1 1 1 3 3 3 3 2 2 1 1 1 1 3 3 1 1 1 
1 2 1 3 3 3 1 3 1 3 1 3 1 3 1 2 1 2 1 3 1 3 1 1 3 
1 2 3 3 1 3 1 3 1 1 1 3 3 3 2 2 1 1 1 1 3 3 1 1 1 
2 2 3 3 1 3 1 3 1 1 1 3 3 3 2 2 1 1 1 1 3 3 1 1 1 
1 2 3 3 1 3 1 3 1 1 1 3 3 3 2 2 1 1 1 1 3 3 1 1 1 
2 2 3 3 1 3 1 3 1 1 1 3 3 3 2 2 1 1 1 1 3 3 1 1 1 
1 1 3 3 3 3 1 1 1 1 3 3 3 3 2 2 1 1 1 1 3 3 1 1 3 

I have tried paste -d " " file1 file2 > output and paste file file2 | sed 's/\t/ /' > file3 but for some reason did not do it. I am getting only the content of file2 in output.

The desired out put is:

1 101 0 0 0 -9 2 2 1 3 1 3 3 3 1 3 1 1 1 3 1 2 1 2 1 3 1 3 1 2 1            
1 102 0 0 0 -9 1 2 3 3 1 1 3 3 1 1 1 1 3 3 2 2 1 1 1 1 3 3 1 1 1            
1 103 0 0 0 -9 2 2 1 3 3 3 1 3 1 3 1 3 1 3 1 2 1 2 1 3 1 3 1 2 1            
1 104 0 0 0 -9 1 2 3 3 3 3 1 1 1 1 3 3 3 3 2 2 1 1 1 1 3 3 1 1 1            
1 105 0 0 0 -9 1 2 1 3 3 3 1 3 1 3 1 3 1 3 1 2 1 2 1 3 1 3 1 1 3            
1 106 0 0 0 -9 1 2 3 3 1 3 1 3 1 1 1 3 3 3 2 2 1 1 1 1 3 3 1 1 1            
1 107 0 0 0 -9 2 2 3 3 1 3 1 3 1 1 1 3 3 3 2 2 1 1 1 1 3 3 1 1 1            
1 108 0 0 0 -9 1 2 3 3 1 3 1 3 1 1 1 3 3 3 2 2 1 1 1 1 3 3 1 1 1            
1 109 0 0 0 -9 2 2 3 3 1 3 1 3 1 1 1 3 3 3 2 2 1 1 1 1 3 3 1 1 1            
1 110 0 0 0 -9 1 1 3 3 3 3 1 1 1 1 3 3 3 3 2 2 1 1 1 1 3 3 1 1 3 

Please note, with less output I am getting the two files joined, but with ^M between them.

Any help is highly appreciated.

Upvotes: 0

Views: 65

Answers (1)

Ignacio Vazquez-Abrams
Ignacio Vazquez-Abrams

Reputation: 798676

file1 has CRLF line endings. Use dos2unix to remove the CRs and get the expected output.

Upvotes: 1

Related Questions