Results 1 to 3 of 3
I am working on Sun OS and utilizing the join command to join 2 files
file1.txt
12.116.0.220|12.116.0.221|1.536|X|X|X|X|X|X|X
12.116.0.240|12.116.0.241|1.536|X|X|X|X|X|X|X
file2.txt
12.116.0.221 |-1 |-1 |-1 |-1
12.116.0.241 |1 |1 |1 |1
I ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
- 06-02-2011 #1Just Joined!
- Join Date
- Jun 2011
- Posts
- 2
join command usage issue
I am working on Sun OS and utilizing the join command to join 2 files
file1.txt
12.116.0.220|12.116.0.221|1.536|X|X|X|X|X|X|X
12.116.0.240|12.116.0.241|1.536|X|X|X|X|X|X|X
file2.txt
12.116.0.221 |-1 |-1 |-1 |-1
12.116.0.241 |1 |1 |1 |1
I want to join these 2 files based on the 2nd field in file1.txt
tried using the below command
join -a 1 -e " " -t: file1.txt file2.txt >file3.dat
I am not getting file3.dat in the expected format.
Can any one please help
- 06-02-2011 #2Just Joined!
- Join Date
- Jun 2011
- Posts
- 2
a small correction. the command i used is:
join -a 1 -e " " -t"\|" -j1 2 file1.txt file2.txt >file3.dat
- 07-10-2011 #3Linux User
- Join Date
- Jan 2005
- Location
- Saint Paul, MN
- Posts
- 394
The problem that you have is that the key in the second file contains a trailing space. You have lots of spaces in fields in the file2.txt
file1.txt
file2.txtCode:12.116.0.220|12.116.0.221|1.536|X|X|X|X|X|X|X 12.116.0.240|12.116.0.241|1.536|X|X|X|X|X|X|X
The command:Code:12.116.0.221|-1 |-1 |-1 |-1 12.116.0.241|1 |1 |1 |1
Note not using the option "-j2" as it is a short cut to specify both fields are the second. When the fields are differnt then you need to use both the "-1 2" and "-2 1" options.Code:join -a 1 -e " " -t\| -1 2 -2 1 file1.txt file2.tx >file3.datt
The output is:
Code:12.116.0.221|12.116.0.220|1.536|X|X|X|X|X|X|X|-1 |-1 |-1 |-1 12.116.0.241|12.116.0.240|1.536|X|X|X|X|X|X|X|1 |1 |1 |1


Reply With Quote

