Re: mutt+sed - deleting line ranges

"[email protected] [sed-users]" <[email protected]>
Newsgroups gmane.editors.sed.user
Message-ID <[email protected]>

 "$q; N" is an operation to workaround the behavior of  "sed" when it encounters
 reading the next line when it's at eof. POSIX sed (not GNU sed) will quickly terminate
 without printing what's there in the pattern space at that point in time when it executes
 the N command on the eof. Hence, the $q; N workarounds this limitation.
 

       sed -e '/^--*$/!b' -e '$q;N' -e '/\nPosted by:/!{P;D;}'   -e  '$q;N'   -e '/\n--*$/d'
 

 It's read from left -> right as:
    a ) skip & print any line not comprising only dashes.
    b ) in case we have a dashes-only line, just check if it's by any chance the last line.
         in case it is the last, then just print it since it's not interesting for us.
    c ) and when it's not the last line, we grab the next line as we enter the interesting phase.
    d ) the pattern space now has two lines in it. 1st portion is good, i.e., dashes only.
         now we need to check for the other portion. incase it's not "Posted by:" then we print the
         1st portion and chop it off & go back with the remaining pattern space, (since it very well
        might be dashes only) to the beginning of the sed code, but without reading the next
       line of input.
    e ) when the 2nd portion of the pattern space is "Posted by:" then we are well on the
         road to a successful match, just need to read one more line to decide. But , as
        before, we check whether we"are at eof, incase yes  we just print the pattern space
       and quit, or we grab the next line and attach it to the pattern space. Now the
      pattern space contains three lines. (= 2 \n chars). portions 1 and 2 are just right for
    a successful match. In case the 3rd line is a dashes only line, then yipeee we have
     our target. Promptly delete it and start all over again. Else, print the three lines
   and start over again.
 

 

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

 * Dan Goldman <dgoldman@... mailto:dgoldman@...> [2016-01-20 00:28]:
 > $q means "quit if last line of file".
 
 ah! :)
 
 > Here is a similar, simpler way that I think
 > works, even as a somewhat long one-liner:
 > /^-----*$/ {N; /Posted by:/ {N; /------$/ d } }
 
 yay! :)
 
 a one-liner right there. no need to change
 to another tool or scripting. happy again. :)
 
 thank you all for contributing!
 
 so my sed script changes+deletes text -
 and i got many text colouring for mutt,
 and also colouring for text in vim
 as well as many commands to fix stuff.
 
 now on to finally adjusting some things
 to asciidoc or markdown or pandoc - and
 finally put it all together in a book
 which is small and yet readable on phones.
 stay tuned! :)
 
 Sven



[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.