Re: mutt+sed - deleting line ranges

"Daniel Goldman [email protected] [sed-users]" <[email protected]>
Newsgroups gmane.editors.sed.user
Message-ID <[email protected]>
A minor point, but assuming the dash-dash-space is a line by itself (is 
that the case?), you might use /^-- $/,$d instead.

The only "visualizer" I know of is Aurelio Jargas' sedsed debugger.

"ex scripts" might help with the task, or might just be interesting for 
anyone not familiar with them. Hardly anybody does ex scripts anymore. 
However, they are very useful, and kind of related to sed scripts.

Anybody good at vi ex mode could be good at using ex scripts.

Of course, "ex scripts" are NOT filters. ex always edits the file in 
place. That is probably a deal-breaker for you. Perhaps an ex script 
could somehow be embedded within a shell script to serve as a filter. Or 
perhaps mutt has another option that would allow ex to be used. Anyway, 
here's how ex would get rid of the lines, using the same vi syntax you 
used (since the syntax is just vi ex mode):

========================

$ cat message.txt
Hello, Dan!!!

------------------------------------
Posted by: Sven Guckes <[email protected]>
------------------------------------

$ cat script.txt
/^Posted by:/-1,//+1d
wq

$ cp message.txt temp.txt
$ cat script.txt | ex -s temp.txt
$ cat temp.txt
Hello, Dan!!!

========================

As you say, the sed hold space can be used for the same end. It's 
arguably more tricky / tedious to program / maintain. awk is another 
possibility: the previous line can be saved to a variable, and printed 
if current line does not match the pattern.

Daniel

On 1/18/2016 5:06 PM, Sven Guckes [sed-users] wrote:
> so my mailer is "mutt" (www.mutt.org) - and it
> has this nifty feature of a "display filter",
> ie messages get filtered through this program before the
> resulting text is shown, so i can change and delete text.
> changing allow me to correct those misspelled words and
> deleting allows for hiding signature and maillist footers.
>
> i had been using "sed" as my filter for many years now.
> the setup for mutt is as easy as this line:
>
>    set display_filter="/bin/sed -f /home/user/guckes/.mutt/df.sed"
>
> so.. it's just a simple "set option=value" command.
>
> getting rid of signatures which are delimited by
> the sigdashes line (das-dash-space) is dead easy:
>
>      /-- /,$d
>
> since that change by yahoo groups my From: line looks like this:
>
>    From: "Sven Guckes [email protected] [sed-users]"
>
> fixing this to "name <address>" is easy within sed:
>
> /^From: .*sed-users/s:"\(.*\) \([^ ]*@[^ ]*\) \[sed-users\]".*:\1 <\2>:
>
> but i should also get rid of seeing those footers now..
> example:
>
> deleting this in the vim editor (www.vim.org) is easy:
>
>    :/Posted by/-1,/Posted by/+1d
>
> that's because you can do easy arithmetic
> on the pattern to get a new line address:
>
>      /pattern/-1,/pattern/+1
>
> but how do you do arithmetic with lines in sed again?
> how to tell sed to "find the matching line, go back one,
> and then delete three (current and next two) lines"?
>
> i am sure the hold and pattern spaces are to be
> used here - but i never quite got the hang of it. :-/
>
> maybe this can even be extended to
> "delete this paragraph if it contains pattern" or
> "delete from line1 to line2 if it contains pattern"?
>
> incidentally - is there some "visualizer"
> to show what sed is currently doing?
> you know, debugger style and all. ;)
>
> Sven
>
>
>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.