< Previous | Contents | Next >
fold – Wrap Each Line To A Specified Length
Folding is the process of breaking lines of text at a specified width. Like our other com- mands, fold accepts either one or more text files or standard input. If we send fold a simple stream of text, we can see how it works:
[me@linuxbox ~]$ echo "The quick brown fox jumped over the lazy dog."
| fold -w 12 The quick br own fox jump ed over the lazy dog.
[me@linuxbox ~]$ echo "The quick brown fox jumped over the lazy dog."
| fold -w 12 The quick br own fox jump ed over the lazy dog.
Here we see fold in action. The text sent by the echo command is broken into seg- ments specified by the -w option. In this example, we specify a line width of 12 charac- ters. If no width is specified, the default is 80 characters. Notice how the lines are broken regardless of word boundaries. The addition of the -s option will cause fold to break the line at the last available space before the line width is reached:
[me@linuxbox ~]$ echo "The quick brown fox jumped over the lazy dog."
| fold -w 12 -s
The quick brown fox jumped over the lazy dog.
[me@linuxbox ~]$ echo "The quick brown fox jumped over the lazy dog."
| fold -w 12 -s
The quick brown fox jumped over the lazy dog.