Search This Blog

Sunday, 8 September 2013

Useful awk examples


A good starting point for awk is here.
  • Print all lines between a start and an end marker:
    awk /START/,/END/ filename | grep -v 'START END'
    The comma separated pattern: /start/,/stop/ {print} is equivalent to the following code:

  • 1:  {   
    2:    if ($0 ~ /start/) {       
    3:      triggered=1;    
    4:    }    
    5:    if (triggered) {  
    6:      print;  
    7:      if ($0 ~ /stop/) {  
    8:        triggered=0;     
    9:      }   
    10:    }  
    11:  }