Once upon a time David P James said... > I use KMail to read this and other mailing lists. When replying to a > message, KMail will look for the last instance of <new > line><dash><dash><space><return> and remove that and everything below > from the reply. A problem occurs however on mailing lists that use that > format to delimit the unsubscribe info when the author has also used it > since KMail will then only remove the unsubscribe info and not the > author's sig. > > The solution seems simple enough - use a KMail filter to pipe messages > through sed to remove the second signature delimiter if there is one. > Here is the sed script I am using but it doesn't work as expected: > > sed s/'^\-\-\ '//2 > > From my understanding of the man and info pages, this should look for > the second instance of <dash><dash><space> and replace it with nothing.
No, the "2" flag will match the second regex on the _line_, not in the file. This is not much use with the anchors (^ and $), since you cannot have multiple matches on a line. Try sed 's/-- //2' on stdin and type: -- hello -- world -- x and you'll get -- hello world -- x ie. it's removed the second "-- ". I'm not sure you can do what you want with sed, since you need to maintain some state, whereas sed seems to be stateless - each line is processed independently of the other lines. However, awk should do what you want: awk 'BEGIN {sepcount=0} /^-- $/ {sepcount+=1; if (sepcount==2) next} {print}' Alternatively, you can use awk to strip the sigs completely: awk '/^-- $/ {nextfile} {print}' -- To UNSUBSCRIBE, email to [EMAIL PROTECTED] with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]