Guest User

http://unix.stackexchange.com/a/88715/7453

a guest
Aug 31st, 2013
235
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Awk 0.41 KB | None | 0 0
  1. Here's a more verbose version of essentially the same thing, hopefully using more readable syntax:
  2.  
  3.  awk '{
  4.         lastLine = currentLine;
  5.         currentLine = $0;
  6.     }
  7.  
  8.     /foo|bar/ \
  9.     {
  10.         getline currentLine
  11.         next
  12.     }
  13.  
  14.     NR > 1 \
  15.     {
  16.         print lastLine;
  17.     }
  18.  
  19.     END \
  20.     {
  21.         if ( currentLine !~ /foo|bar/ )
  22.             print currentLine;
  23.     }
  24.     ' file.txt
Add Comment
Please, Sign In to add comment