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]
On Thu, 17 Jun 1999, Jeff 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?
You could also use the "fold" command if you wish.
fold <filename> | lpr
Do a "man fold" for additional details
> 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.
>
--
Sanjay
|
|