#14 Formatting Long Lines

If you're lucky, your Unix system already includes the fmt command, a program that's remarkably useful if you work with text with any frequency. From reformatting email to filling in paragraphs in documents (that is, making sure that as many words as possible are on each line of the text), fmt is a helpful utility to know.

But some Unix systems don't include fmt, particularly legacy systems at universities, which often have a fairly minimalistic implementation. As it turns out, the nroff command, which has been part of Unix since the very beginning, can be utilized in a short shell script to achieve the same result of wrapping long lines and filling in short lines to even up line lengths.

The Code

 #!/bin/sh # ...

Get Wicked Cool Shell Scripts now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.