The Single UNIX ® Specification, Version 2
Copyright © 1997 The Open Group

 NAME

fold - filter for folding lines

 SYNOPSIS



fold [-bs][-w width][file...]

 DESCRIPTION

The fold utility is a filter that will fold lines from its input files, breaking the lines to have a maximum of width column positions (or bytes, if the -b option is specified). Lines will be broken by the insertion of a newline character such that each output line (referred to later in this section as a segment) is the maximum width possible that does not exceed the specified number of column positions (or bytes). A line will not be broken in the middle of a character. The behaviour is undefined if width is less than the number of columns any single character in the input would occupy.

If the carriage-return, backspace or tab characters are encountered in the input, and the -b option is not specified, they will be treated specially:

backspace
The current count of line width will be decremented by one, although the count never will become negative. The fold utility will not insert a newline character immediately before or after any backspace character.
carriage-return
The current count of line width will be set to zero. The fold utility will not insert a newline character immediately before or after any carriage-return character.
tab
Each tab character encountered will advance the column position pointer to the next tab stop. Tab stops will be at each column position n such that n modulo 8 equals 1.

 OPTIONS

The fold utility supports the XBD specification, Utility Syntax Guidelines  .

The following options are supported:

-b
Count width in bytes rather than column positions.
-s
If a segment of a line contains a blank character within the first width column positions (or bytes), break the line after the last such blank character meeting the width constraints. If there is no blank character meeting the requirements, the -s option will have no effect for that output segment of the input line.
-w width
Specify the maximum line length, in column positions (or bytes if -b is specified). The results are unspecified if width is not a positive decimal number. The default value is 80.

 OPERANDS

The following operand is supported:
file
A pathname of a text file to be folded. If no file operands are specified, the standard input will be used.

 STDIN

The standard input will be used only if no file operands are specified. See the INPUT FILES section.

 INPUT FILES

If the -b option is specified, the input files must be text files except that the lines are not limited to {LINE_MAX} bytes in length. If the -b option is not specified, the input files must be text files.

 ENVIRONMENT VARIABLES

The following environment variables affect the execution of fold:
LANG
Provide a default value for the internationalisation variables that are unset or null. If LANG is unset or null, the corresponding value from the implementation-dependent default locale will be used. If any of the internationalisation variables contains an invalid setting, the utility will behave as if none of the variables had been defined.
LC_ALL
If set to a non-empty string value, override the values of all the other internationalisation variables.
LC_CTYPE
Determine the locale for the interpretation of sequences of bytes of text data as characters (for example, single- as opposed to multi-byte characters in arguments and input files), and for the determination of the width in column positions each character would occupy on a constant-width font output device.
LC_MESSAGES
Determine the locale that should be used to affect the format and contents of diagnostic messages written to standard error.
NLSPATH
Determine the location of message catalogues for the processing of LC_MESSAGES .

 ASYNCHRONOUS EVENTS

Default.

 STDOUT

The standard output will be a file containing a sequence of characters whose order will be preserved from the input files, possibly with inserted newline characters.

 STDERR

Used only for diagnostic messages.

 OUTPUT FILES

None.

 EXTENDED DESCRIPTION

None.

 EXIT STATUS

The following exit values are returned:
0
All input files were processed successfully.
>0
An error occurred.

 CONSEQUENCES OF ERRORS

Default.

 APPLICATION USAGE

The cut and fold utilities can be used to create text files out of files with arbitrary line lengths. The cut utility should be used when the number of lines (or records) needs to remain constant. The fold utility should be used when the contents of long lines need to be kept contiguous.

The fold utility is frequently used to send text files to printers that truncate, rather than fold, lines wider than the printer is able to print (usually 80 or 132 column positions).

 EXAMPLES

An example invocation that submits a file of possibly long lines to the printer (under the assumption that the user knows the line width of the printer to be assigned by lp):

fold -w 132 bigfile | lp

 FUTURE DIRECTIONS

None.

 SEE ALSO

cut.

UNIX ® is a registered Trademark of The Open Group.
Copyright © 1997 The Open Group
[ Main Index | XSH | XCU | XBD | XCURSES | XNS ]