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

Russell Senior seniorr at aracnet.com
Wed Oct 17 14:26:07 UTC 2007


>>>>> "Paul" == Paul Heinlein <heinlein at madboa.com> writes:

Paul> 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.

Paul> The added bonus is that fmt works great within vi(m). For
Paul> instance, to wrap a really long line of text, [...]

Oh, you just had to go an bring up vi.  In emacs, just put your cursor
in the paragraph and type:  M-q

   M-q runs the command fill-paragraph
      which is an interactive compiled Lisp function in `textmodes/fill'.
   (fill-paragraph ARG)

   Fill paragraph at or after point.  Prefix ARG means justify as
   well.  If `sentence-end-double-space' is non-nil, then period
   followed by one space does not end a sentence, so don't break a
   line there.  the variable `fill-column' controls the width for
   filling.

   If `fill-paragraph-function' is non-nil, we call it (passing our
   argument to it), and if it returns non-nil, we simply return its
   value.

   If `fill-paragraph-function' is nil, return the `fill-prefix' used
   for filling.

Lots fewer keystrokes! ;-)


-- 
Russell Senior         ``I have nine fingers; you have ten.''
seniorr at aracnet.com



More information about the PLUG mailing list