If you've worked with databases, you'll probably know what to do with the UNIX join command; see your online manual page. If you don't have a database (as far as you know!), you'll still probably have a use for join : combining or "joining" two column-format files. join searches certain columns in the files; when it finds columns that match one another, it "glues the lines together" at that column. This is easiest to show with an example.
I needed to summarize the information in thousands of email messages
under the MH mail system.
MH made that easy: it has one command (scan
) that gave me
almost all the information I wanted about each message in the format I wanted.
But I also had to use
Here's the file that I told scan
The columns (message number, email address, comment, name, and date
sent) are separated with commas (
0001,firstname.lastname@example.org,,Andy Ernbaum,19901219 0002,email@example.com,,Zoe Doan,19910104 0003,firstname.lastname@example.org,,Head Honcho,19910105 ...
Here's the file from wc and awk with the message number and number of lines:
0001,11 0002,5 0003,187 ...
Then, this join
command joined the two files at their first
The output file looked like:
0001,email@example.com,,Andy Ernbaum,19901219,11 0002,firstname.lastname@example.org,,Zoe Doan,19910104,5 0003,email@example.com,,Head Honcho,19910105,187 ...
Of course, join can do a lot more than this simple example shows. See your online manual page.