#!/usr/bin/awk -f # rselection # Select rows (and the header line) # where the values in a given column # match a given pattern. # usage: awk -f rsel.awk column=col pattern=pat input # - elb 2007-05-15 BEGIN { FS = "\t" } 1 == NR { # Header (column names meta data) for (i = 1; i <= NF; i++ ) { n = split( $i, a, /: */ ) if ( 1 < n ) { # then column has a data type. columnumber[a[1]] = i # Just get the name. } else { columnumber[$i] = i } } print # Make sure heading is in the output. next # But not twice. } $columnumber[column] ~ pattern { print }