procmail
[Top] [All Lists]

Re: blank line consolidation/strippage

2001-11-19 15:40:18
Sean followed up,

| Thanks, but that reduces all blocks of blank lines to a SINGLE newline.

No, it reduces them to one EMPTY line (or to two newlines, if you prefer).
If it reduced them to a single newline, there would be no empty lines at
all, just a solid block of text.

| I want to retain the logical spacing that multiple blank lines is
| sometimes used to denote (one blank line may separate paragraphs, two or
| more are sometimes used to "shift gears" so to speak).

OK, thanks for clarifying.  It probably takes the kind of code you've
already written.  The exception would be the case where the entire text fits
into sed's hold space:

 sed -e1h -e '1!H' -e '$ !d' -eg \
   -e 's/^\n*//' -e '/\n*$//' -e 's/\(\n\n\n)\n*/\1/g'

| This is saved as a sed file invoked using the -f argument, because for the
| life of me, I can't get that multiline sed command to run within
| procmail - as a shell script or sed file, the arguments work - but if I
| use the command as shown at the top of this message, sed balks:

There are two other approaches besides having the instructions in a separate
file:

1. Use repeated -e options, one for each instruction.
2. If your sed groks semicolons, string instructions together with
semicolons instead of newlines.

Note that #2 is limited, because certain sed instructions must be terminated
by a newline rather than a semicolon.

| | sed -e '/^$/N \
| /^\n$/{N \
| /^\n\n$/D \
| }'

That would become,

  | sed -e '/^$/N' -e '/^\n$/{' -eN -e '/^\n\n$/D' -e'}'

for example.  Apparently your sed allows combining the second and third -e's
into a single -e '/^\n$/{N', but not all do.




_______________________________________________
procmail mailing list
procmail(_at_)lists(_dot_)RWTH-Aachen(_dot_)DE
http://MailMan.RWTH-Aachen.DE/mailman/listinfo/procmail

<Prev in Thread] Current Thread [Next in Thread>