Sunday, May 5, 2024
2
rated 0 times [  2] [ 0]  / answers: 1 / hits: 1193  / 2 Years ago, sat, september 17, 2022, 1:10:33

suppose this is my file which its name is myFile1



1 10
2 20
3 30
4 40
5 50
6 60


know I want to add my another columns to this. This column is on the file which is myFile2.



10
11
12
13
14
15
16


. is there any way to add myFile2 to myFile1 to create this table :



1 10 10
2 20 11
3 30 12
4 40 13
5 50 14
6 60 15

More From » text-processing

 Answers
1

paste is pretty handy here but it'll punish you if the number of values is unequal:



$ paste -d' ' myFile{1,2}
1 10 10
2 20 11
3 30 12
4 40 13
5 50 14
6 60 15
16


If you wanted to arbitrarily limit the lines used in the second file to the first, you can, it's just going to be a bit slower and use more RAM (not that it matters on such a small data set).



$ paste -d' ' myFile1 <(head -n$(cat myFile1 | wc -l) myFile2)
1 10 10
2 20 11
3 30 12
4 40 13
5 50 14
6 60 15

[#23983] Sunday, September 18, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
brellked

Total Points: 63
Total Questions: 107
Total Answers: 104

Location: Morocco
Member since Fri, May 22, 2020
4 Years ago
;