1FOLD(1P)                   POSIX Programmer's Manual                  FOLD(1P)
2
3
4

PROLOG

6       This  manual  page is part of the POSIX Programmer's Manual.  The Linux
7       implementation of this interface may differ (consult the  corresponding
8       Linux  manual page for details of Linux behavior), or the interface may
9       not be implemented on Linux.
10

NAME

12       fold - filter for folding lines
13

SYNOPSIS

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

DESCRIPTION

18       The fold utility is a filter that  shall  fold  lines  from  its  input
19       files,  breaking  the lines to have a maximum of width column positions
20       (or bytes, if the -b option is specified). Lines shall be broken by the
21       insertion  of a <newline> such that each output line (referred to later
22       in this section as a segment) is the maximum width possible  that  does
23       not  exceed the specified number of column positions (or bytes). A line
24       shall not be broken in the middle of  a  character.   The  behavior  is
25       undefined  if width is less than the number of columns any single char‐
26       acter in the input would occupy.
27
28       If the <carriage-return>s, <backspace>s, or <tab>s are  encountered  in
29       the  input,  and  the -b option is not specified, they shall be treated
30       specially:
31
32       <backspace>
33              The current count of line width shall  be  decremented  by  one,
34              although the count never shall become negative. The fold utility
35              shall not insert a <newline> immediately  before  or  after  any
36              <backspace>.
37
38       <carriage-return>
39
40              The  current  count of line width shall be set to zero. The fold
41              utility shall not insert a <newline> immediately before or after
42              any <carriage-return>.
43
44       <tab>  Each <tab> encountered shall advance the column position pointer
45              to the next tab stop. Tab stops shall be at each column position
46              n such that n modulo 8 equals 1.
47
48

OPTIONS

50       The  fold  utility  shall  conform  to  the  Base Definitions volume of
51       IEEE Std 1003.1-2001, Section 12.2, Utility Syntax Guidelines.
52
53       The following options shall be supported:
54
55       -b     Count width in bytes rather than column positions.
56
57       -s     If a segment of a line contains a <blank> within the first width
58              column  positions (or bytes), break the line after the last such
59              <blank> meeting the width constraints. If there  is  no  <blank>
60              meeting the requirements, the -s option shall have no effect for
61              that output segment of the input line.
62
63       -w  width
64              Specify the maximum line length, in column positions  (or  bytes
65              if -b is specified). The results are unspecified if width is not
66              a positive decimal number. The default value shall be 80.
67
68

OPERANDS

70       The following operand shall be supported:
71
72       file   A pathname of a text file to be folded. If no file operands  are
73              specified, the standard input shall be used.
74
75

STDIN

77       The  standard  input  shall be used only if no file operands are speci‐
78       fied. See the INPUT FILES section.
79

INPUT FILES

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

ENVIRONMENT VARIABLES

86       The following environment variables shall affect the execution of fold:
87
88       LANG   Provide a default value for the  internationalization  variables
89              that  are  unset  or  null.  (See the Base Definitions volume of
90              IEEE Std 1003.1-2001, Section  8.2,  Internationalization  Vari‐
91              ables  for the precedence of internationalization variables used
92              to determine the values of locale categories.)
93
94       LC_ALL If set to a non-empty string value, override the values  of  all
95              the other internationalization variables.
96
97       LC_CTYPE
98              Determine  the  locale  for  the  interpretation of sequences of
99              bytes of text data as characters (for  example,  single-byte  as
100              opposed  to multi-byte characters in arguments and input files),
101              and for the determination of the width in column positions  each
102              character would occupy on a constant-width font output device.
103
104       LC_MESSAGES
105              Determine  the  locale  that should be used to affect the format
106              and contents of diagnostic messages written to standard error.
107
108       NLSPATH
109              Determine the location of message catalogs for the processing of
110              LC_MESSAGES .
111
112

ASYNCHRONOUS EVENTS

114       Default.
115

STDOUT

117       The standard output shall be a file containing a sequence of characters
118       whose order shall be preserved from  the  input  files,  possibly  with
119       inserted <newline>s.
120

STDERR

122       The standard error shall be used only for diagnostic messages.
123

OUTPUT FILES

125       None.
126

EXTENDED DESCRIPTION

128       None.
129

EXIT STATUS

131       The following exit values shall be returned:
132
133        0     All input files were processed successfully.
134
135       >0     An error occurred.
136
137

CONSEQUENCES OF ERRORS

139       Default.
140
141       The following sections are informative.
142

APPLICATION USAGE

144       The  cut  and  fold  utilities  can be used to create text files out of
145       files with arbitrary line lengths. The cut utility should be used  when
146       the  number  of  lines  (or records) needs to remain constant. The fold
147       utility should be used when the contents of long lines need to be  kept
148       contiguous.
149
150       The fold utility is frequently used to send text files to printers that
151       truncate, rather than fold, lines wider than the  printer  is  able  to
152       print (usually 80 or 132 column positions).
153

EXAMPLES

155       An example invocation that submits a file of possibly long lines to the
156       printer (under the assumption that the user knows the line width of the
157       printer to be assigned by lp):
158
159
160              fold -w 132 bigfile | lp
161

RATIONALE

163       Although terminal input in canonical processing mode requires the erase
164       character (frequently set to <backspace>) to erase the previous charac‐
165       ter  (not byte or column position), terminal output is not buffered and
166       is extremely difficult, if not  impossible,  to  parse  correctly;  the
167       interpretation  depends  entirely  on the physical device that actually
168       displays/prints/stores  the  output.  In  all  known  internationalized
169       implementations,  the utilities producing output for mixed column-width
170       output assume that a <backspace> backs up one column position and  out‐
171       puts  enough  <backspace>s to return to the start of the character when
172       <backspace> is used to provide local line motions to support  underlin‐
173       ing  and  emboldening  operations.  Since fold without the -b option is
174       dealing with these same constraints, <backspace> is always  treated  as
175       backing up one column position rather than backing up one character.
176
177       Historical  versions of the fold utility assumed 1 byte was one charac‐
178       ter and occupied one column position  when  written  out.  This  is  no
179       longer  always true. Since the most common usage of fold is believed to
180       be folding long lines for output to limited-length output devices, this
181       capability  was  preserved as the default case. The -b option was added
182       so that applications could fold files with arbitrary length lines  into
183       text files that could then be processed by the standard utilities. Note
184       that although the width for the -b option is in bytes, a line is  never
185       split in the middle of a character.  (It is unspecified what happens if
186       a width is specified that is too small to hold a single character found
187       in the input followed by a <newline>.)
188
189       The  tab stops are hardcoded to be every eighth column to meet histori‐
190       cal practice. No new method of specifying other tab stops was invented.
191

FUTURE DIRECTIONS

193       None.
194

SEE ALSO

196       cut
197
199       Portions of this text are reprinted and reproduced in  electronic  form
200       from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology
201       -- Portable Operating System Interface (POSIX),  The  Open  Group  Base
202       Specifications  Issue  6,  Copyright  (C) 2001-2003 by the Institute of
203       Electrical and Electronics Engineers, Inc and The Open  Group.  In  the
204       event of any discrepancy between this version and the original IEEE and
205       The Open Group Standard, the original IEEE and The Open Group  Standard
206       is  the  referee document. The original Standard can be obtained online
207       at http://www.opengroup.org/unix/online.html .
208
209
210
211IEEE/The Open Group                  2003                             FOLD(1P)
Impressum