shithub: riscv

ref: f0f2d452c873255dec4b3359b3f93e349be0f2c5
dir: /sys/src/9/port/mkextract/

View raw version
#!/bin/rc

switch($#*){
case [012]
	echo usage: mkextract [-u] field n file... >[1=2]
	exit 1
}

switch($1){
case -u
	flag=$1; shift
case *
	flag=''
}

field=$1
n=$2
shift 2

fn select {
	awk '

		BEGIN			{ doprint=0 }
		/^$/			{ next }
		/^#/			{ next }
		doprint && /^[^	]/	{ doprint=0 }
		doprint			{ print $'^$n^' }
		$1 ~ "^'^$field^'$"	{ doprint=1; next }
	' $*
}

switch($flag){
case -u
	select $* | sort -u
case *
	select $*
}