#33 Wrapping Only Long Lines

One limitation of the fmt command and its shell script equivalent, Script #14, is that they wrap and fill everything they encounter, whether it makes sense to do so or not. This can mess up email (wrapping your .signature is not good, for example) and many other input file formats.

What if you have a document in which you want to wrap just the long lines but leave everything else intact? With the default set of commands available to a Unix user, there's only one possible way to accomplish this: Explicitly step through each line in an editor, feeding the long ones to fmt one by one (for example, in vi you could move the cursor onto the line in question and then use !$fmt to accomplish this).

Yet Unix has plenty ...

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.