Re: reducing redundant lines, partially

"[email protected] [sed-users]" <[email protected]> 21 Nov 2016 20:36:11 -0800
Newsgroups gmane.editors.sed.user
Message-ID <[email protected]>
The normal flow of sed is that a line from the input file is read in to the pattern space and all the sed commands are applied on this pattern space in the order they appear(barring any change of flow commands like b, t). Once the end of sed code is reached the by-now pattern space is printed to stdout.
 Then the cycle is started all over again using the next line from the input file.
 Notice that the pattern space just one line all the while.
 

 The N;P;D method is different than the above.
Think of the N;P;D paradigm in "sed" as the sliding-window technique wherein you hold two lines in the pattern space at any time. Then perform some munging on the pattern space and print the head portion of the pattern space post munging and then chop it off and go back for more. 

 Actually the little-known "list" command [l] can be of great help in the sliding-window operations. It lists the pattern space in a user-friendly format wherein the nonprintable control characters in the pattern space are shown via their symbol, take for example, the newline as \n, etc.
 

 For in this case place the [l] command at certain locations to monitor the growth of the pattern space, like as,
 

 sed -e '
    l
    :loop
        $!N
        l
        s/^\([^:]*\)\(.*\)\n\1\(:.*\)$/\1\2\3/
     tloop
     P;D
 ' yourfile
 

 Then observe the evolution of the pattern space. This will hopefully answer your queries regarding the regex.
 



[Non-text portions of this message have been removed]