Small shell tools for text editing

Slashdot it! Delicious Share on Facebook Tweet! Digg!

Combining Texts

You use the paste tool for this. Each text file is considered a "column" in the target file. The "montage" works as follows:

paste [FILE1] [FILE2]

You can, of course, direct the output to a new file.

The tool does not in any way evaluate what is on each line. It just pairs them up. Figure 8 shows an example.

Figure 8: Text files combined as columns using paste.

Joining Two Files

With the join command, you join the rows of two tables using a common key. The two tables need to be sorted first. To gain a better understanding of how this works, you can take a look at some of the sample files first. The format of the command is join [-OPTION] [FILE1] [FILE2] .

Table 14 shows the most important options. If you omit any field values, the first column of the file is used by default.

Table 14

Figure 9 shows how join works. In the first example, without any options, the first field is the common key. In the second example, all non-joinable lines in the first file are printed to the output. Finally, all incorrect sorting error messages are removed and the columns for joining get printed. Of course, any further possible pairings are omitted due to any sorting errors.

Figure 9: Joining text files using join.

Buy this article as PDF

Express-Checkout as PDF

Pages: 1

Price $0.99
(incl. VAT)

Buy Ubuntu User

SINGLE ISSUES
 
SUBSCRIPTIONS
 
TABLET & SMARTPHONE APPS
Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content