Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- http://sed.sourceforge.net/sed1line.txt
- sed -n 'G; s/n/&&/; /^([ -~]*n).*n1/d; s/n//; h; P'
- sed -n ' # -n: by default, do not print
- G # Append hold space to current input line
- s/n/&&/ # Add empty line after current input line
- /^([ -~]*n).*n1/d # If the current input line is repeated in the hold space, skip this line
- # Otherwise, clean up for storing all input in hold space:
- s/n// # Remove empty line after current input line
- h # Copy entire pattern space back to hold space
- P # Print current input line'
- ^ # Look at beginning of line (i.e. beginning of pattern space)
- ( # This starts group 1
- [ -~] # Any printable character (in the C locale)
- * # Any number of times
- n # Followed by a newline
- ) # End of group 1 -- it contains the current input line
- .*n # Skip any amount of lines as necessary
- 1 # Another occurrence of the current input line, with newline and all
- vvv
- sed -n 'G; s/n/&&/; /^([^n]*n).*n1/d; s/n//; h; P'
- ^^^
- # The standard sed loop
- my $hold = "";
- while ($my pattern = <>) {
- chomp $pattern;
- $pattern = "$patternn$hold"; # G
- $pattern =~ s/(n)/$1$1/; # s/n/&&/
- if ($pattern =~ /^([^n]*n).*n1/) { # /…/
- next; # d
- }
- $pattern =~ s/n//; # s/n//
- $hold = $pattern; # h
- $pattern =~ /^([^n]*n?)/; print $1; # P
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement