Complete.Org: Mailing Lists: Archives: discussion: June 1999:
Re: [aclug-L] How to wrap lines in a file
Home

Re: [aclug-L] How to wrap lines in a file

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: "'aclug-L@xxxxxxxxxxxx'" <aclug-L@xxxxxxxxxxxx>
Subject: Re: [aclug-L] How to wrap lines in a file
From: Jeff <schaller@xxxxxxxxxxxxx>
Date: Thu, 17 Jun 1999 14:50:43 -0500 (CDT)
Reply-to: aclug-L@xxxxxxxxxxxx

On Thu, 17 Jun 1999, Bates, Rod wrote:

> Is there a common filter that will wrap long lines in a text
> file,  producing a file with shorter lines, but with the fragment
> from the right on the next line?  

Do you want the fragment to be _joined_ with the next line, or to be on a
line by itself?

ie:

short part short part short part -- long part long part
second line second line.

turns into:

short part short part short part --
long part long part
second line second line

or

short part short part short part --
long part long part second line second line.

?

The first option is easy enough:
while (<>) {
  if (70 < length $_) { substr($_, 70, 0) = "\n" }
  print;
}

More tricky if you want to break at a space (but what if there isn't a
space?)

while (<>) {
  if (70 < length $) {
    $i = index $_, " ", 70;
    if ($i > 0) { 
      substr($_, $i, 0) = "\n" } 
    else { warn "Couldn't break line\n"; }
  }
  print;
}

Trickier if you want the 2nd case above; what if the new second line ends
up longer than WRAP_LENGTH?

Or, if it's short, you can load it up in pico and lean on control-j.
But no, I don't know of any filters off-hand that do that.

-jeff
-- 
But scientists, who ought to know
Assure us that it must be so.
Oh, let us never, never doubt
What nobody is sure about.       -- Hilaire Belloc


[Prev in Thread] Current Thread [Next in Thread]