moreutils completes the shell's toolbox

Slashdot it! Delicious Share on Facebook Tweet! Digg!

zrun

Tools like parallel-moreutils tend to generate unusual effects, particularly with commands that are somewhat more complex. On the other hand, the small command zrun is easy to understand and also use by virtue of its simple syntax.

$ zrun <program with arguments> <compressed data>

This program decompresses archives given as its arguments on the fly, thus saving space on the drive. In the current version, the program works with archives with formats including GZIP, BZIP2, Z, XZ, LZMA, and LZO.

A typical use case involves editing a compressed text file. An attempt to to open this kind of file with an editor, such as nano , does not work (Figure 1). The zrun tool makes things look quite different (Figure 2). You can see in the title bar of the editor that zrun has generated a temporary decompressed file, which is then handed to the editor.

Figure 1: Loading compressed files in the editor usually yields garbage.
Figure 2: Data that has been decompressed on the fly with zrun provides the desired results in the editor.

zrun deletes the decompressed temporary file after you've finished with it; therefore, all of the modifications are lost unless you save your edited file to a new uncompressed version under a different name. It is up to you to compress the new version of your file again.

zrun has an additional feature. If you create a link to zrun in the form of z<program> , then the link starts as zrun <program> . For example, create a link:

ln -s /bin/zrun /tmp/znano

You have now generated a temporary command called znano . Running znano <file> acts exactly the same as zrun nano <file> .

combine

A second group of moreutils commands is used for processing or testing files. There are many differences among these programs. Most target text files, which is not surprising since these kind of files have been used for a multitude of tasks for many years. For example, configuration files and many log files are in plain text format.

Traditional Unix tools are very powerful for working with text files. These tools are all available under Linux. Even so, there are some special maneuvers required for certain tasks. Such tasks would include logical linking of text files, something which the combine command makes possible.

This command combines all of the lines of two files via a logical operator and then shows the results. The operators include AND (logical and), OR (logical or), NOT (not), and XOR (exclusive or). With the AND operator, only those lines that exist both in the first and second file are returned. The content of the text lines is irrelevant to the combine operation; however, it scans the text in its entirety.

Below is the syntax for the command. You can replace every file with standard input using - . The operators you apply are recognized by the program independently of the way they are written.

$ combine <file> <Operator> <file>

Listings 4 and 5 show the two files used to demonstrate the different operations you can carry out on different operations using combine . Listing 6, for example, shows what happens when you use the XOR filter on A and B: You get all of the lines from the files that are not identical in both.

Listing 4

File A

a1
a2
a3
a4

Listing 5

File B

a1
b2
b3
a4
b5

Listing 6

A XOR B

$ combine A xor B
a2
a3
b2
b3
b5

The files A (Listing 4) and B (Listing 5) have a two lines in common. Otherwise all of the lines are different. The tool filters the latter out via XOR . It is worth mentioning here that the B file is one line longer than the A file. Nonetheless, b5 appears in the output. This means that the tool even processes empty lines.

In Listing 7, you can see what happens when you use AND to combine A and B. Only the lines that are the same in both are shown.

Listing 7

A AND B

$ combine A and B
a1
a4

Buy this article as PDF

Express-Checkout as PDF

Pages: 7

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