procmail
[Top] [All Lists]

Re: How to remove multiple newlines

2004-07-14 19:56:36
shoved in my todo file on my home directory. However, usually there is a
leading and trailing newline, after formail gets rid of all the headers.

I have used this awk thing to get rid of empty lines in msgs from a
certain list:

  ## filter out stupid empty lines (looks like double-spacing)
  ## (solaris 2.7 awk needs f!=0, not just f)
  #:0 bfw
  #| awk 'f!=0 {f=0; print; next}; $0 ~ /^$/ {f=1; next}; {print}'

It won't remove more than one empty line at a time though. I'd program a
little double state machine in awk. The leading bit is easy:

gawk '
    BEGIN { lead=1 }
    lead && $0 ~ /^$/ { next }
    { lead=0 }
    $0 !~ /^$/ { printf "%s\n", lines $0; lines=""; next }
    { lines=lines "\n" }
'

This will treat whitespace-only lines as non-empty. Awks other than GNU
may need more work to deal with their retardations.

Volker

-- 
Volker Kuhlmann                 is possibly list0570 with the domain in header
http://volker.dnsalias.net/             Please do not CC list postings to me.

____________________________________________________________
procmail mailing list   Procmail homepage: http://www.procmail.org/
procmail(_at_)lists(_dot_)RWTH-Aachen(_dot_)DE
http://MailMan.RWTH-Aachen.DE/mailman/listinfo/procmail