Re: awk script to insert blank line between matching patterns
Troy Piggins wrote:
> I'm not too good with awk, but I don't think this can be done
> with sed.
>
> I pass email/usenet messages through my message filter to 'clean'
> them up. Currently I have the script below [1](with some personal
> lines removed). As you can see, the message is piped through
> sed, then t-prot (a tidying up script I found by Jochen Striepe),
> then finally 'mail-to-filter' (a perl script by Gary Johnson).
>
> I want to add an awk script that adds a blank line to messages just
> above the signature delimiter if there isn't a blank line there
> already. So if the end of the email ends with:
>
> ...
> Thanks,
> Fred
> --
> Fred's sig here
> blahblah
>
> I'd like my display filter to add blank line like this:
>
> ...
> Thanks,
> Fred
>
> --
> Fred's sig here
> blahblah
>
> If there was already a blank line there, then do nothing.
> Any ideas or pushes in the right direction?
>
> [1]
There are some more ways:
sed '/^--/{g;s/^$/--/;t;s/.*/\n--/};h'
awk 'BEGIN{RS=ORS="\n--"}sub(/\n*$/,"\n")'
perl -0777pe 's/(?<=\S)(?=\n--)/\n/'
perl -00pe 's/(?=\n--)/\n/'
Xicheng
|