#!/bin/sh : ' : This script removes lines which are repeated later. The text for : equality is done by default on the first field, however if $1 is present, : it is done only on awk-field $1. Explicitly specifying field 1 sets NN : to a lower value (for efficiency) than defaulting to field 1 : : Author: Corey Satten, corey @ cac.washington.edu, 4/4/90 : http://staff.washington.edu/corey : ' PATH=/bin:/usr/bin:/usr/ucb:/usr/local/bin:. AWK=/usr/local/bin/mawk # mawk has longer line limit than awk NN=200 # substr of $0 to split into fields # is a field specified? case "$1" in '') FLD=1;; 1) FLD=1; NN=40; shift;; -[0-9]*) FLD="-($1)"; shift;; # forgive negative field numbers *) FLD=$1; shift;; esac exec $AWK ' # now do the real work with awk { n = split(x=substr($0,1,'$NN'),f);# only split first NN chars to fields if (ln=lno[f['$FLD']]) { val[ln] = $0 # new value replaces old one } else { val[lno[f['$FLD']]= ++ctr] = $0 } } END { for (i=1; i<=ctr; ++i) printf("%s\n", val[i]) } ' ${1+"$@"}