Re: mutt+sed - RE1...RE2...RE3

"[email protected] [sed-users]" <[email protected]> 20 Jan 2016 05:08:30 -0800
Newsgroups gmane.editors.sed.user
Message-ID <[email protected]>
 

---In [email protected], <maillists-yahoo@...> wrote :

 * Daniel Goldman <dgoldman@... mailto:dgoldman@...> [2016-01-19 13:57]:
 > A minor point, but assuming the dash-dash-space is a line by
 > itself (is that the case?), you might use /^-- $/,$d instead.
 
 oops.. yes - i simply had forgotten to type the BOL/EOL anchors.
 so, indeed, "/^-- $/,$d" is what i use in my display_filter.
 
 > The only "visualizer" I know of is Aurelio Jargas' sedsed debugger.
 
 why - Aurelio's debugger, of course! :-)
 
 but i never really worked with it.
 is anyone using it? can you please
 share some examples with screenshots?
 
 > "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.
 
 the in-place-editing is a deal-breaker, indeed.
 reading those mails certainly requires a filter.
 
 once i am replying ti message i am within vim.
 and i do use a lot of commands+macros then.
 but i really do not want to change using
 sed as my display_filter in mutt.
 
 > 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.
 
 you can practically use *anything* as the display_filter. :-)
 set display_filter="~/bin/script"
 
 but i do not want to rewrite all that sed does for me in "ex". ;)
 
 > 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.
 
 i have been thinking about using awk for a long time now..
 but most things so far were simply changes on one line -
 so there hasnt been any good reason for this yes.
 besides - sed is really really FAST! :)
 
 but once i get the feeling for using hold+pattern space more
 maybe i can also tackle those problems i had described
 which concern conditions over multiple lines.
 
 i'd describe these kind of problems like this:
 RE1...RE2...RE3
 
 the patterns RE1 and RE3 give the "frame" -
 and RE2 comes somewhere in between -
 hence the dots to describe that.
 
 the basic idea is to require that given frame
 for making changes/deletions to pattern RE2.
 read this as "make changes/deletions to RE2
 only iff it is surrounded by RE1 and RE3".
 
 one of these is deleting those extra "signatures":
 
 ------------------------------------
 Posted by: ...
 ------------------------------------
 
 here, the patterns are like these:
 RE1="^-{37}$"
 RE2="^Posted by:"
 RE3="^-{37}$"
 
 a possible notation:
 |RE1|RE2|RE3|/RE2/d
 
 so "/RE2/d" simply deletes all lines
 within the RE1,RE3 block matching RE2.
 
 it is pretty obvious that such constructs can
 become arbitrarily large in the data they amount.
 however, maybe the can be restricted in some way?
 something like "test for max N lines"?
 
 maybe this will look pretty weird in sed,
 and can be described more easily in awk.
 a nice syntax would certainly be a
 reason to switch to awk then. ;)
 
> so.. if you have any ideas - i am really
> looking forward to some ideas handling
> those RE1...RE2...RE3 problems. :)
 
> Sven
 

 One straightforward way for this is using the sed's range operator.
 

 BEGIN='^--*$'

 END='^--*$'
 MID='Posted by[:]'
 

 sed -e "
 /$BEGIN/,/$END/!d                             ; # skip non-interesting portion
 /$MID/{
           # this mid always occurs inside of begin-end portion
           s/$/ this is a comment on the mid-portion/     ; # YMMV
         }
 "

 

 HTH
 -Rakesh
 




[Non-text portions of this message have been removed]
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.