Advertisement
Guest User

Untitled

a guest
Mar 6th, 2013
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.56 KB | None | 0 0
  1. http://sed.sourceforge.net/sed1line.txt
  2.  
  3. sed -n 'G; s/n/&&/; /^([ -~]*n).*n1/d; s/n//; h; P'
  4.  
  5. sed -n ' # -n: by default, do not print
  6. G # Append hold space to current input line
  7. s/n/&&/ # Add empty line after current input line
  8. /^([ -~]*n).*n1/d # If the current input line is repeated in the hold space, skip this line
  9. # Otherwise, clean up for storing all input in hold space:
  10. s/n// # Remove empty line after current input line
  11. h # Copy entire pattern space back to hold space
  12. P # Print current input line'
  13.  
  14. ^ # Look at beginning of line (i.e. beginning of pattern space)
  15. ( # This starts group 1
  16. [ -~] # Any printable character (in the C locale)
  17. * # Any number of times
  18. n # Followed by a newline
  19. ) # End of group 1 -- it contains the current input line
  20. .*n # Skip any amount of lines as necessary
  21. 1 # Another occurrence of the current input line, with newline and all
  22.  
  23. vvv
  24. sed -n 'G; s/n/&&/; /^([^n]*n).*n1/d; s/n//; h; P'
  25. ^^^
  26.  
  27. # The standard sed loop
  28. my $hold = "";
  29. while ($my pattern = <>) {
  30. chomp $pattern;
  31.  
  32. $pattern = "$patternn$hold"; # G
  33. $pattern =~ s/(n)/$1$1/; # s/n/&&/
  34. if ($pattern =~ /^([^n]*n).*n1/) { # /…/
  35. next; # d
  36. }
  37. $pattern =~ s/n//; # s/n//
  38. $hold = $pattern; # h
  39. $pattern =~ /^([^n]*n?)/; print $1; # P
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement