Wednesday, December 26, 2007
"join" is used for joining two input lines having an identical join field. Here is a good example to show its usefulness.
$ cat file1
life is beautiful:1997:Yes
Employee of the Month:2006:Yes
$ cat file2
life is beautiful:8.4
Employee of the Month:5.3
life is beautiful:1997:8.4:Yes
Employee of the Month:2006:5.3:Yes
This can be achieved using "join"
$ join -t ":" -j 1 -o 1.1 1.2 2.2 1.3 file1 file2
A live example would be getting username and its default login shell listed in /etc/passwd and group name from /etc/group.
Numeric value of "group" is 4th field in /etc/passwd and 3rd field in /etc/group file.
$ join -t ":" -1 4 -2 3 -o 1.1 2.1 1.7 /etc/passwd /etc/group
© Jadu Saikia www.UNIXCL.com