xref: /plan9/sys/src/9/port/mkextract (revision 6a9fc400c33447ef5e1cda7185cb4de2c8e8010e)
1#!/bin/rc
2
3switch($#*){
4case [012]
5	echo usage: mkextract [-u] field n file... >[1=2]
6	exit 1
7}
8
9switch($1){
10case -u
11	flag=$1; shift
12case *
13	flag=''
14}
15
16field=$1
17n=$2
18shift 2
19
20fn select {
21	awk '
22
23		BEGIN			{ doprint=0 }
24		/^$/			{ next }
25		/^#/			{ next }
26		doprint && /^[^	]/	{ doprint=0 }
27		doprint			{ print $'^$n^' }
28		$1 ~ "^'^$field^'$"	{ doprint=1; next }
29	' $*
30}
31
32switch($flag){
33case -u
34	select $* | sort -u
35case *
36	select $*
37}
38