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

NAME

6       fold - filter for folding lines
7

SYNOPSIS

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

DESCRIPTION

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

OPTIONS

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

OPERANDS

64       The following operand shall be supported:
65
66       file   A  pathname of a text file to be folded. If no file operands are
67              specified, the standard input shall be used.
68
69

STDIN

71       The standard input shall be used only if no file  operands  are  speci‐
72       fied. See the INPUT FILES section.
73

INPUT FILES

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

ENVIRONMENT VARIABLES

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

ASYNCHRONOUS EVENTS

108       Default.
109

STDOUT

111       The standard output shall be a file containing a sequence of characters
112       whose  order  shall  be  preserved  from the input files, possibly with
113       inserted <newline>s.
114

STDERR

116       The standard error shall be used only for diagnostic messages.
117

OUTPUT FILES

119       None.
120

EXTENDED DESCRIPTION

122       None.
123

EXIT STATUS

125       The following exit values shall be returned:
126
127        0     All input files were processed successfully.
128
129       >0     An error occurred.
130
131

CONSEQUENCES OF ERRORS

133       Default.
134
135       The following sections are informative.
136

APPLICATION USAGE

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

EXAMPLES

149       An example invocation that submits a file of possibly long lines to the
150       printer (under the assumption that the user knows the line width of the
151       printer to be assigned by lp):
152
153
154              fold -w 132 bigfile | lp
155

RATIONALE

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

FUTURE DIRECTIONS

187       None.
188

SEE ALSO

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