Previous | Table of Contents | Next |
DESCRIPTION
The external fold command is a filter that folds lines longer than 80 characters into lines less than 80 characters . You can specify the width of the line instead of using the default of 80.
If tabs are present in the input data, you may want to send the data through expand first, then pipe it into fold .
COMMAND FORMAT
Following is the general format of the fold command.
fold [ -wwidth ] [ file_list ] fold [ -width ] [ file_list ]
| |
---|---|
BSD (Berkeley) | |
fold [ -width ] [ file_list ] | |
|
Options
The following option and its argument may be used to control how fold functions.
- width -wwidth | Specifies the width of the output line in characters. The default is 80. The width should always be a multiple of your tab length if tabs exist within the input data. Usually tabs are set every eight spaces. |
Arguments
The following argument may be passed to the fold command.
file_list | A list of files to be read and checked for lines longer than the specified or default width. |
DIAGNOSTICS AND BUGS
The fold command may interfere with underlining in the input text.
RELATED COMMANDS
Refer to the expand command described in Module 46.
RELATED FILES
The fold command reads a list of files or uses the standard input if no files are specified as arguments. The output is written to the standard output.
APPLICATIONS
You use fold to break long lines down into shorter more readable lines. This is a very useful function if you have a terminal that does not wrap its lines onto the next line. It may also be used for printers that do not know how to wrap lines longer than a certain width onto the next line. By using fold you can perform the wrapping function before the data reaches the output device.
Some terminals automatically wrap long output lines onto the next line. This looks good but may cause problems with commands that attempt to count displayed lines. If the line is longer than 80 characters, it takes up two lines of your terminal screen. Programs like pr format the output based on the number of physical lines read. Thus a line may scroll off the top of your screen or your printed output may not be aligned on the paper correctly, because the number of physical lines does not match the number of displayed lines.
The fold command may be used to correct this problem, because it breaks the long lines down into shorter physical lines, making other commands count the proper number of physical lines.
TYPICAL OPERATION
In this activity you use the fold command to wrap long lines onto the next output line. First you must create a file with lines longer than 80 characters. Begin at the shell prompt.
cj> vi xwide This is a line of text that is longer than 80 characters. It wraps around to the next line on some terminals but not on others. Therefore we use fold.<CR> Another line just for filling up space. The fold command cuts these lines off at 80 characters (or there about) and displays the remainder of the line on the next output line.<Escape>
Previous | Table of Contents | Next |