WRAP —Word-wrap English text to fit a specified number of columns.

Syntax:
WRAP /A:attribs /C: /CP:n /D /F:fmt /G:n,m /H /J /N:n /N /P /Q /R /S /T:n /W:width /Z:char filename…

/A:attribsattributes mask; valid flags are -ACEHIORS
/C:ncondense repeated spaces in input text
/CP:ninterpret non-Unicode input text using code page n
/Ddisable special handling of soft hyphens (character 173 / 0xAD)
/F:fmtspecifies the format for input text; fmt is one of:
   0 — best guess (default)
   1 — unformatted (line breaks are used only to end paragraphs)
   2 — prewrapped (line breaks are used to wrap text)
   3 — unformatted, with blank lines between paragraphs
/G:n,mindent all paragraphs n spaces; if m is specified, it’s the indent for the second and later lines
/Hdisplay filenames
/Jjustify right margins
/N:nminimum characters left on each line to split at a hyphen; 0 disables breaking at hyphens
/Ppage output
/Ndisable features
/Qreplace ASCII quotes and apostrophes with Unicode open and close quotes
/Rremove hyphens from line ends
/Ssearch in subdirectories for matching filenames
/T:ntab stops every n spaces
/W:widthdesired width of output text
/Z:chardefine a forced line-break character
Range options are also supported.

The WRAP command word-wraps English text to fit a specified width. It can be used as a filter reading from standard input, or it can read from one or more files specified on the command line. The resulting text is written to standard output; it can be piped or redirected.

If you want to pipe to WRAP, remember that pipes open a new shell. To pipe to a plugin command, you must either ensure that the plugin is loaded in the transient shell, e.g. by installing the .DLL file in the shell’s PlugIns directory; or else use temporary files or an in-process pipe.

You may specify more than one filename; wildcards and directory aliases are supported. You can search recursively into subdirectories for matching files with /S. @File lists and internet files are supported. You may also specify CLIP: to wrap text from the clipboard.

‘Width’ here refers to a specified number of character positions, or columns. All characters are assumed to have the same width. The word-wrapped output should have neat, reasonably uniform line lengths when viewed or printed in a fixed-pitch font such as Courier, or displayed in a console window. Note that the specifed width includes the final newline character; if you specify a width of 80, then up to 79 printable characters may appear on a line.

Note:  This command is designed specifically for use with English prose. It may give weird or undesired results when used on source code, program output, HTML, or whatnot. It makes Anglocentric assumptions that may not be appropriate to other languages.

If standard input (stdin) is redirected, WRAP will read from stdin before any filenames specified on the command line. If no filenames are specified, then WRAP will read from stdin whether it is redirected or not. If /H is used, each file’s name will be printed before it is processed. (For standard input, <stdin> will be shown.)

Output width: /W:width sets the desired width in characters for the output text. Width may be from 40 to 512. If no /W:width is specified, the default is the console width if output is to the console, or defaults to 100 columns if output is redirected. (You can set an environment variable COLUMNS to change this default.) If you type just a /W without a colon or width, then the current console width is assumed; this is useful if you are redirecting WRAP’s output but want it wrapped to the console width anyway, e.g. for piping to LIST.

Text format: Text files use line-break characters in different ways. In some files, line break characters are used only to mark where a line end should occur: the end of a paragraph. In other files, line breaks are used to wrap text to some desired width. You can use /F:n to tell WRAP how to handle line breaks. /F:1 indicates that the text is unformatted, with line breaks only at the ends of paragraphs. WRAP will honor all line breaks, and add an extra blank line after each paragraph. /F:2 means that the input text is prewrapped, having line breaks within paragraphs and even within sentences. WRAP will skip single line breaks, honoring only sequences of two or more in a row. /F:3 is also for unformatted text and acts like /F:1, but does not insert a blank line after each paragraph; use this option to wrap the output from DEHTML. If you specify /F:0 or do not specify any /F:n, WRAP will attempt to guess how the input text is formatted. (Guessing is not reliable when there isn’t much input text.)

Tab size: The /T:n option controls the expansion of tab characters. By default, tab stops are every four columns (set an environment variable TABSIZE to change this default). /T:8 would make tabs eight columns wide. /T:0 disables special handling of tab characters, treating them like any other character; this will probably bollix word-wrapping and is not recommended. n may be 0 to 20.

Breaking at hyphens: WRAP will usually break lines at spaces. It may also break a line after a hyphen, if all of the following are true: (1) the character before the hyphen is a letter, and the following character is either a letter or a digit; (2) at least three characters, not counting the hyphen, will remain at the end of the line; and (3) at least three characters will move to the start of the following line. So, for example, if the phrase true-blue fell near the end of a line, WRAP might break the line after the hyphen, since true and blue have four letters each. The phrases do-nothing and derring-do would not be divided, however, since splitting either one would leave a two-letter do on a line by itself. You can adjust this behavior with /N:n, which sets the minimum number of characters for both lines. If you specify /N:4 then at least four characters, not counting the hyphen, must remain on each line. /N:0 prevents WRAP from breaking lines after hyphens.

Removing hyphens: If /R is used, WRAP may discard a hyphen at the end of a line if the preceding character was a letter, and if the first character on the following line is also a letter. Without /R, WRAP retains all hyphens from line ends.

Forced indentation: The /G:n option forcibly indents each new paragraph n spaces (not tabs.) Any indentation in the input text will be lost. n must be 0 to 20. /G:0 will strip all leading whitespace, leaving text flush with the left margin. The optional second value, if present, indents the second and later lines m spaces; m is also 0 to 20. You might use /G:0,4 to produce a hanging indent. If /G: is not specified, any indentation in the input text is preserved.

Condensing spaces: The /C:n option allows you to condense runs of consecutive spaces in the input text. Any sequence of more than n spaces will be truncated. Only spaces (character 32) are counted, not other whitespace characters. Spaces generated by the program itself (e.g. by expanding tabs or indenting paragraphs) will not be condensed. n must be 0 to 10; if n is 0, spaces are not condensed (the default.) This option might be useful for packing output text just a little more tightly; if the original text file had extra spaces inserted to justify margins; or if you are one of those unfortunates who suffer a violent reaction to the sight of two spaces after a period.

Quotes replacement: /Q causes WRAP to replace generic ASCII apostrophes and quote marks ( ' and " ) with Unicode open and close quote marks (   and    ). The new quote marks may or may not look different from the originals, depending on how they are displayed and the font used. If the output is displayed in a non-Unicode font, the curly quotes will be lost or mangled. You can set some environment variables to control this feature.

Text encoding: WRAP automatically detects Unicode text files. If the file is not Unicode, the command has no way of detecting the character encoding; the default Windows code page is assumed. You can specify a different code page for non-Unicode text files with /CP:n. Most single-byte (i.e., Western) code pages are supported, but multibyte code pages (Chinese, Japanese, Korean) are not. This option only affects non-Unicode files.

Forced line break: /Z:char defines a forced line-break character. char may be entered as either a single character, or as a decimal or hexadecimal (prefixed with 0x) character code. If a matching character is found in the input file or stream, WRAP will end the current line and begin a new one.

Disabling features: /N with suboptions disables features:

/NBdo not write a Byte Order Mark
/NDdo not search into hidden directories; only useful with /S
/NHdo not add a hyphen when breaking a word
/NJdo not search into junctions; only useful with /S

You can combine these, e.g. /NDJ.


These variables may be set to a numeric value to modify the command’s default behavior:

COLUMNS:sets the default width when output is redirected and /W is not specified. Legal values are 40 to 512.
TABSIZE:sets the default number of columns between tab stops when /T is not specified. Legal values are 1 to 20.

wrap /w:100 "Fishy Story.txt"