Open System Services Shell and Utilities Reference Manual (G06.29+, H06.08+, J06.03+)
User Commands (d - f) fold(1)
NAME
fold - Breaks lines in a file
SYNOPSIS
fold [-bs][-w width][file ...]
The fold command breaks lines in the specified files, or in the standard input file if no files are
specified, to have maximum width.
FLAGS
-b Counts width in bytes rather than in column positions. In this case, the lines are not lim-
ited to LINE_MAX bytes.
-s If a segment of a line contains a blank character within the first width column positions
(or bytes), breaks the line after the last such blank character, meeting the width con-
straints. If there is no blank character meeting the requirements, the -s flag does not
affect that output segment of the input line.
-w width Specifies the maximum width to which lines should be folded in column positions (or
bytes if -b is specified). The default value is 80.
DESCRIPTION
The fold command is a filter that folds lines from its input files, breaking the lines to have a max-
imum of width column positions (or bytes, if the -b flag is specified). The fold command breaks
lines by inserting a newline character so that each output line is the maximum width possible that
does not exceed the specified number of column positions (or bytes). A line cannot be broken in
the middle of a character.
The fold command is often used to send text files to line printers that truncate, rather than fold,
lines wider than the printer is able to print (usually 80 or 132 column positions).
If the <backspace>, <tab>,or<carriage-return> characters are encountered in the input and the
-b flag is not specified, these characters are treated specially:
<backspace>
The current count of line width is decremented by one, although the count never
becomes negative. The fold command does not insert a newline character immediately
before or after any backspace character.
<tab> Each tab character encountered advances the column position pointer to the position of
the next tab stop. Tab stops are at each column position number, such that number
modulo 8 equals 1.
<carriage-return>
The current count of the line width is set to 0 (zero). The fold command does not insert
a newline immediately before or after any carriage-return character.
Note that the fold command may affect any underlining that is present.
EXAMPLES
The fold command can be used to prepare files to be joined side-by-side with the paste command.
You might want to display these two files, az and AZ, side-by-side:
aaaa bbbb cccc dddd eeee ffff gggg hhhh iiii jjjj kkkk llll mmmm
nnnn oooo pppp qqqq rrrr ssss tttt uuuu vvvv wwww xxxx yyyy zzzz
AAAA BBBB CCCC DDDD EEEE FFFF GGGG HHHH IIII JJJJ KKKK LLLL MMMM
NNNN OOOO PPPP QQQQ RRRR SSSS TTTT UUUU VVVV WWWW XXXX YYYY ZZZZ
527188-021 Hewlett-Packard Company 3−157