Re: Blank lines not being squeezed

From: Chris F.A. Johnson (c.fa.johnson_at_rogers.com)
Date: 03/26/04


Date: 26 Mar 2004 07:14:47 GMT

On Fri, 26 Mar 2004 at 04:40 GMT, Fred Ma wrote:
> "Chris F.A. Johnson" wrote:
>>
>> On Fri, 26 Mar 2004 at 04:03 GMT, Fred Ma wrote:
>> >
>> > I was using various methods to turn a few man pages
>> > into compact text pages. In bash notation:
>> >
>> > man man | PAGER -s | col -bx >| TextFile.txt
>>
>> man man | col -bx | tr -s '\n' >| TextFile.txt
>
> You seem to be answering alot of my questions.

   It's more fun than working. :)

> Thanks for pointing out the tr command. I wonder,
> though, why "more" or "less" would not behave in
> the way that I expected when its output is piped
> or redirected?

   I don't see any documentation regarding it, but I believe that
   nothing is done to the file when output is not to a terminal.

> They do a nice job otherwise,
> because the single blank line they leave behind
> helps to space things out a bit.

   Use cat -s instead of tr -s "\n".

   If your cat doesn't have the -s option (it's not in POSIX, but
   all versions I've seen do have it), use this awk script:

awk '
 /^$/ && ++empty > 1 { next }
 /./ { empty = 0 }
 { print }
'

   Incidentally, if you just want to view a man page without multiple
   blank lines, since man already pipes the file through $PAGER, you
   can give it the option this way (if $PAGER-less):

LESS="$LESS -s" man man

   Or (if $PAGER=more):

MORE="$MORE -s" man man

-- 
    Chris F.A. Johnson                  http://cfaj.freeshell.org/shell
    ===================================================================
    My code (if any) in this post is copyright 2004, Chris F.A. Johnson
    and may be copied under the terms of the GNU General Public License