Search This Blog

Friday, May 08, 2015

Use variable in search pattern in awk

Passing a variable to awk and using it in the search pattern.



awk -v string="$STRING" -f  script.awk  [filename]

Script extract:

$0 ~ string {
      
       print $0;
}

Note:

        On Solaris use nawk.