.\" .\" Sun Microsystems, Inc. gratefully acknowledges The Open Group for .\" permission to reproduce portions of its copyrighted documentation. .\" Original documentation from The Open Group can be obtained online at .\" http://www.opengroup.org/bookstore/. .\" .\" The Institute of Electrical and Electronics Engineers and The Open .\" Group, have given us permission to reprint portions of their .\" documentation. .\" .\" In the following statement, the phrase ``this text'' refers to portions .\" of the system documentation. .\" .\" Portions of this text are reprinted and reproduced in electronic form .\" in the SunOS Reference Manual, from IEEE Std 1003.1, 2004 Edition, .\" Standard for Information Technology -- Portable Operating System .\" Interface (POSIX), The Open Group Base Specifications Issue 6, .\" Copyright (C) 2001-2004 by the Institute of Electrical and Electronics .\" Engineers, Inc and The Open Group. In the event of any discrepancy .\" between these versions and the original IEEE and The Open Group .\" Standard, the original IEEE and The Open Group Standard is the referee .\" document. The original Standard can be obtained online at .\" http://www.opengroup.org/unix/online.html. .\" .\" This notice shall appear on any product containing this material. .\" .\" The contents of this file are subject to the terms of the .\" Common Development and Distribution License (the "License"). .\" You may not use this file except in compliance with the License. .\" .\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE .\" or http://www.opensolaris.org/os/licensing. .\" See the License for the specific language governing permissions .\" and limitations under the License. .\" .\" When distributing Covered Code, include this CDDL HEADER in each .\" file and include the License file at usr/src/OPENSOLARIS.LICENSE. .\" If applicable, add the following below this CDDL HEADER, with the .\" fields enclosed by brackets "[]" replaced with your own identifying .\" information: Portions Copyright [yyyy] [name of copyright owner] .\" .\" .\" Copyright 1989 AT&T .\" Portions Copyright (c) 1992, X/Open Company Limited. All Rights Reserved. .\" Copyright (c) 1995, Sun Microsystems, Inc. All Rights Reserved. .\" .TH FOLD 1 "Feb 1, 1995" .SH NAME fold \- filter for folding lines .SH SYNOPSIS .LP .nf \fBfold\fR [\fB-bs\fR] [\fB-w\fR \fIwidth\fR | \fB-width\fR] [\fIfile\fR]... .fi .SH DESCRIPTION .sp .LP The \fBfold\fR utility is a filter that will fold lines from its input files, breaking the lines to have a maximum of \fIwidth\fR column positions (or bytes, if the \fB-b\fR 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 behavior is undefined if \fIwidth\fR is less than the number of columns any single character in the input would occupy. .sp .LP If the CARRIAGE-RETURN, BACKSPACE, or TAB characters are encountered in the input, and the \fB-b\fR option is not specified, they will be treated specially: .sp .ne 2 .na \fBBACKSPACE \fR .ad .RS 20n The current count of line width will be decremented by one, although the count never will become negative. \fBfold\fR will not insert a NEWLINE character immediately before or after any BACKSPACE character. .RE .sp .ne 2 .na \fBCARRIAGE-RETURN \fR .ad .RS 20n The current count of line width will be set to \fB0\fR. \fBfold\fR will not insert a NEWLINE character immediately before or after any CARRIAGE-RETURN character. .RE .sp .ne 2 .na \fBTAB \fR .ad .RS 20n Each TAB character encountered will advance the column position pointer to the next tab stop. Tab stops will be at each column position \fIn\fR such that \fIn\fR modulo 8 equals 1. .RE .SH OPTIONS .sp .LP The following options are supported: .sp .ne 2 .na \fB\fB-b\fR \fR .ad .RS 20n Counts \fIwidth\fR in bytes rather than column positions. .RE .sp .ne 2 .na \fB\fB-s\fR \fR .ad .RS 20n If a segment of a line contains a blank character within the first \fIwidth\fR column positions (or bytes), breaks the line after the last such blank character meeting the width constraints. If there is no blank character meeting the requirements, the \fB-s\fR option will have no effect for that output segment of the input line. .RE .sp .ne 2 .na \fB\fB-w\fR \fIwidth\fR\fB|\fR\fB-\fR\fIwidth\fR \fR .ad .RS 20n Specifies the maximum line length, in column positions (or bytes if \fB-b\fR is specified). If \fIwidth\fR is not a positive decimal number, an error is returned. The default value is 80. .RE .SH OPERANDS .sp .LP The following operand is supported: .sp .ne 2 .na \fB\fB\fIfile\fR\fR \fR .ad .RS 9n A path name of a text file to be folded. If no \fIfile\fR operands are specified, the standard input will be used. .RE .SH EXAMPLES .LP \fBExample 1 \fRSubmitting a file of possibly long lines to the line printer .sp .LP An example invocation that submits a file of possibly long lines to the line printer (under the assumption that the user knows the line width of the printer to be assigned by \fBlp\fR(1)): .sp .in +2 .nf example% \fBfold -w 132 bigfile | lp\fR .fi .in -2 .sp .SH ENVIRONMENT VARIABLES .sp .LP See \fBenviron\fR(5) for descriptions of the following environment variables that affect the execution of \fBfold\fR: \fBLANG\fR, \fBLC_ALL\fR, \fBLC_CTYPE\fR, \fBLC_MESSAGES\fR, and \fBNLSPATH\fR. .SH EXIT STATUS .sp .LP The following exit values are returned: .sp .ne 2 .na \fB\fB0\fR \fR .ad .RS 7n All input files were processed successfully. .RE .sp .ne 2 .na \fB\fB>0\fR \fR .ad .RS 7n An error occurred. .RE .SH ATTRIBUTES .sp .LP See \fBattributes\fR(5) for descriptions of the following attributes: .sp .sp .TS box; c | c l | l . ATTRIBUTE TYPE ATTRIBUTE VALUE _ CSI enabled _ Interface Stability Standard .TE .SH SEE ALSO .sp .LP \fBcut\fR(1), \fBpr\fR(1), \fBattributes\fR(5), \fBenviron\fR(5), \fBstandards\fR(5) .SH NOTES .sp .LP \fBfold\fR and \fBcut\fR(1) can be used to create text files out of files with arbitrary line lengths. \fBfold\fR should be used when the contents of long lines need to be kept contiguous. \fBcut\fR should be used when the number of lines (or records) needs to remain constant. .sp .LP \fBfold\fR is frequently 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). .sp .LP \fBfold\fR may not work correctly if underlining is present.