#!/bin/sed -f # # clipquoted.sed -- Clip quoted text # # PUBLIC DOMAIN # Dedicated to the Public Domain (to see how bad of a sed script # writer I really am *grin*) by Chad Walstrom # on Thu, 18 May 2006 16:21:03 -0500 # # DESCRIPTION # Prints all unquoted text and first quoted line. Replaces # subsequent quoted lines with a single > ...[snip]... string. # # Additionally, snip off "Original Message" crapola. # # EXAMPLE # I subscribe to a list of non-techie homebrewers. Here's my # procmail recipe: # # # Saint Paul Home Brewers Club (SPHBC) # :0 H # * ^TO_(sphbc@sphbc\.org) # { # :0 bwf # | $HOME/bin/clipquote.sed # # PF_DEST="lists/. lists/sphbc/${YEAR_MONTH}/." # } # # # BUGS # This is probably terribly inefficient, but I wanted to see if I # could do it. # ################################################################################ # Copy first line into hold space 1{ h d } # label top of script :top # if line isn't quoted /^>/! { # Quit at Original Message /[Oo]riginal [Mm]essage/ { x p q } # swap with hold space x # if prev line is 'snipped' /^SNIPPED/ { # else, insert "> ...[snip]..." i\ > ...[snip]... # delete pattern d b top } b end } # If line is quoted /^>/ { # swap with hold space x # If prev line snipped, copy back to hold space and delete pattern space /^SNIPPED/ { h d b top } # if prev line quoted /^>/ { # print pattern space p # change pattern to "SNIPPED" s/.*/SNIPPED/ # copy to hold space h # delete pattern d # back up to the top b top } # else print and back to top b end } :end # If this is the end of the file $!n ${ # re-swap the hold space, print, and quit x G q } # Otherwise, back up to the top b top # End of script