Useful Unix Commands: fmt
For a while, I’ve been keeping a file of useful Unix commands and interesting usage examples. I’ll post some of those here from time to time.
I’ll start with a nice little utility
that reformats text to a given line width: fmt. The basic syntax is
quite simple: fmt -80 myfile.txt formats the text
contained in myfile.txt to a maximum line width of 80 characters and outputs
it on standard out (like most Unix commands, fmt will take its
input from standard input if you omit file name).
fmt inserts line breaks as necessary (any whitespace character is a valid insertion point), and also removes unncessary line breaks. Line breaks
that mark the end of a paragraph will be preserved (the end of a paragraph is defined as a line break immediately followed by another, or a line break on an empty line).
Additional command-line options apply uniform spacing (-u for the GNU version, -s for the BSD version), format mail header lines
sensibly (-m BSD only), and specifiy a goal length the output
lines should get as close as possible to, while not exceeding the specified maximum line width (fmt
lines of text. For this, only the -c option has to be specified
(and the input file(s) if the input is not read from standard input).
Of course there are much more powerful text processing utilites available on
any given Unix system, but often simple utilities like fmt are
completely sufficient and much easier to learn
Resources:





Sebastian said,
September 14, 2004 @ 08:13
This seems to be just the right article series for me…
I have been using Linux intensively for the last year now, but I still go like “Wow! It’s good to know such a thing exists!” when people mention a command to me that everybody except me has known for ages.
Robert said,
October 7, 2004 @ 18:14
For Mac OS X there is TextMachine (software.wolle77.de)!