Chapter 13
Text Manipulation
In Unix and Linux, everything is a file. An awful lot of those files are plain ASCII text, and there are a lot of tools in Unix for manipulating text. This is another example of the principle that tools should “do one thing and do it well.” This chapter introduces a mixture of some of the best-known text manipulating tools and some of the less well-known ones.
These text conversion filters can generally take their input either from stdin or from a file named on the command line. They then send their output to stdout. This means that although they can be used directly on files, they are often even more useful in a pipeline. So cut -d: -f7 /etc/passwd | sort | uniq will list all of the different shells configured in /etc/passwd in one single pipeline.
This chapter looks in detail at some of the best, most common, and most useful text manipulation tools available in the Unix and GNU/Linux environments. On the GNU side of things, most of these tools are now contained within the coreutils package; there used to be fileutils, shellutils, and textutils, until they were all merged into the coreutils package.