Join utility in linux
To merge line by lines(line 1 of file1 is merged to line 1 of file2 and etc) within two files. But the join utility is used to merge if there is common field in both file and if values are identical to each other. Join does not work line by line. It works with all the lines between file to search for identical values.
A example will make you more clear. We have id_age.txt and id_dept.txt file and data are shown below. Both join and paste are shown below.
# cat id_age.txt
024401 28
024402 26
024434 23
# cat id_dept.txt
024401 CIT
024434 CSE
024438 EEE
# paste id_age.txt id_dept.txt
024401 28 024401 CIT
024402 26 024434 CSE
024434 23 024438 EEE
# join id_age.txt id_dept.txt
024401 28 CIT
024434 23 CSE
Note that the id 024434 is on the 2nd line of the id_dept.txt but the id 024434 is on the 3rd line of the id_age.txt and merge is done successfully.
A example will make you more clear. We have id_age.txt and id_dept.txt file and data are shown below. Both join and paste are shown below.
# cat id_age.txt
024401 28
024402 26
024434 23
# cat id_dept.txt
024401 CIT
024434 CSE
024438 EEE
# paste id_age.txt id_dept.txt
024401 28 024401 CIT
024402 26 024434 CSE
024434 23 024438 EEE
# join id_age.txt id_dept.txt
024401 28 CIT
024434 23 CSE
Note that the id 024434 is on the 2nd line of the id_dept.txt but the id 024434 is on the 3rd line of the id_age.txt and merge is done successfully.
Comments
Post a Comment