Small shell tools for text editing

Slashdot it! Delicious Share on Facebook Tweet! Digg!

Statistics with wc

The wc command is interesting if you need to pay particular attention to characters, words, or lines. For example, you can use wc to provide parameters to prepare for printing. The wc command can be applied directly to files or can be piped. Table 10 shows the main options.

Table 10

The GNU version of wc described here provides, among other things, the option to extract the number of characters in the longest line of the document. You can use this information to create an attractive print output for encscript or latex , because this is an important factor in the choice of font size or page orientation. Running the program without options gives you the line, word, or byte count. Figure 6 provides some examples.

Figure 6: Examples of wc.

Numbering Lines

You can impose line numbering for (print) output independently of an editing (or other) application. The nl program works with text files and pipes. Table 11 lists the options.

Table 11

For example, you would do the following:

cat e.txt | nl -v 10 -i10 -ba -w 3-nrz

to number all lines in the piped data with a starting value of 10 and an increment of 10, making the numbers three characters (000 ) wide.

Buy this article as PDF

Express-Checkout as PDF

Pages: 1

Price $0.99
(incl. VAT)

Buy Ubuntu User

Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content