fmtx
Reformat each paragraph of text.
Mirrors GNU fmt. Run it as fmtx, or as gnux fmtx.
Synopsis
fmtx [-WIDTH] [OPTION]... [FILE]...GNU reference
Description
fmtx fills and joins the lines of each paragraph so that they come as close as possible to a goal width without exceeding the maximum width, and writes the result to standard output. With no FILE, or when FILE is -, it reads standard input. Paragraphs are separated by blank lines and by changes of indentation; the indentation of each paragraph is kept. The line breaks are chosen as GNU fmt chooses them, minimizing raggedness over the whole paragraph and avoiding breaking after the first word of a sentence or before its last. -w WIDTH sets the maximum width (75 by default, at most 2500), also written -WIDTH; -g WIDTH sets the goal (93% of the maximum by default, and without -w the maximum becomes the goal plus 10). -c (crown margin) keeps the indentation of the first two lines and aligns the rest with the second; -t (tagged paragraph) is the same, except that a first line indented like the second is a paragraph of its own. -s only splits long lines and never joins short ones, which suits code. -u puts one space between words and two after sentences. -p STRING reformats only the lines that begin with STRING (after any indentation) and puts it back on each output line; the other lines are copied unchanged. A sentence ends at '.', '?' or '!' followed by the end of the line or two spaces, as in GNU fmt.
Permissions
Needs read permission on each FILE and search permission on the directories leading to it. Nothing is ever modified.
Use cases
- Rewrapping a commit message, README paragraph or email to a fixed width.
- Joining hard-wrapped text into evenly filled lines.
- Reflowing comment blocks with
-p'#' or-p'//'. - Splitting overlong lines without joining short ones with
-s. - Normalizing spacing between words and sentences with
-u.
Flags
-c, --crown-margin preserve indentation of first two lines
-g, --goal string goal width (default of 93% of width)
--help display this help and exit
-p, --prefix STRING reformat only lines beginning with STRING, reattaching the prefix to reformatted lines
-s, --split-only split long lines, but do not refill
-t, --tagged-paragraph indentation of first line different from second
-u, --uniform-spacing one space between words, two after sentences
--version output version information and exit
-w, --width WIDTH maximum line width (default of 75 columns)Examples
Tidy up a text file whose lines were edited into ragged lengths
fmtx notes.txtRewrap a commit message to the 72 columns git log expects
fmtx -w 72 message.txtRun an old script that uses the obsolete width form
fmtx -60 notes.txtShorten overlong lines in a script or list without merging its lines
fmtx -s -w 80 script.txtReflow a block of shell comments after editing them
fmtx -p '#' -w 72 config.shNormalize spacing in a document pasted from several sources
fmtx -u draft.txtReflow a list whose items have a hanging indent
fmtx -t list.txtReflow a letter that indents its first line
fmtx -c letter.txtAim for even 70-column lines, never exceeding 80
fmtx -w 80 -g 70 notes.txtReflow text coming out of another command
catx a.txt b.txt | fmtx -w 66Save a cleanly wrapped final copy of a draft
fmtx -w 72 draft.txt > final.txtPreview a reflowed file in the portable gnux shell, the same on every OS
gnux shell -c 'fmtx -w 60 notes.txt | headx'Options
Each option has a page of its own, with its usage and examples.
- -c, --crown-margin: Preserve indentation of first two lines.
- -g, --goal: Goal width (default of 93% of width).
- -p, --prefix: Reformat only lines beginning with STRING, reattaching the prefix to reformatted lines.
- -s, --split-only: Split long lines, but do not refill.
- -t, --tagged-paragraph: Indentation of first line different from second.
- -u, --uniform-spacing: One space between words, two after sentences.
- -w, --width: Maximum line width (default of 75 columns).
Exit status
| Status | Meaning |
|---|---|
| 0 | success: every operand was processed |
| 1 | failure: an operand could not be processed (diagnosed on standard error), or a command-line mistake |
Help in the terminal
fmtx --help # options, first examples, exit status
gnux help fmtx # this page: the full manual
gnux help fmtx --OPTION # one option in depth, with its examples