Advertisement
homer512

sed print 4

Apr 26th, 2014
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.40 KB | None | 0 0
  1. #!/bin/sed -nf
  2.  
  3. # Prints the line containing a regular expression and next 4 lines
  4.  
  5. # check if line matches regex
  6. /foo/{
  7.     # set hold space to 4
  8.     x
  9.     s/.*/4/
  10.     x
  11.     # print line and restart
  12.     p
  13.     d
  14. }
  15.  
  16. # if no match, check whether hold space is between 1 and 4
  17. x
  18. /[1-4]/{
  19.     # decrement integer in hold space
  20.     y/1234/0123/
  21.     x
  22.     # print line and restart
  23.     p
  24.     d
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement