Hack #11-> Join Command

Join command combines lines from two files based on a common field.

In the example below, we have two files – employee.txt and salary.txt.

Both have employee-id as common field. So, we can use join command

to combine the data from these two files using employee-id as shown

below.

$ cat employee.txt

100 Jason Smith

200 John Doe

300 Sanjay Gupta

400 Ashok Sharma

$ cat bonus.txt

100 $5,000

200 $500

300 $3,000

400 $1,250

$ join employee.txt bonus.txt

100 Jason Smith $5,000

200 John Doe $500

300 Sanjay Gupta $3,000

400 Ashok Sharma $1,250

Advertisements

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s