[PLUG] some awk-fu or perl to word wrap a text file?

Paul Heinlein heinlein at madboa.com
Wed Oct 17 14:02:05 UTC 2007


On Tue, 16 Oct 2007, Michael Rasmussen wrote:

> Don J. wrote:
>> My perl skills are still in the very preliminary stages ... might 
>> anyone know how I could take a large text file that has no hard 
>> wrapping, and apply hard wraps every 80 characters or so? Any 
>> ideas?
>
> fmt -w 80 large_file > new_file
> see `man fmt` for details
>
> Not Perl, not a reinvented wheel.

The added bonus is that fmt works great within vi(m). For instance, 
to wrap a really long line of text, get the cursor to the beginning of 
the line and (in command mode) type

:.!fmt

Or if you've got a paragraph with a really ragged right side, position 
the cursor at the beginning of the paragraph and (in command mode) 
type

!}fmt

-- 
Paul Heinlein <> heinlein at madboa.com <> http://www.madboa.com/



More information about the PLUG mailing list