#! /bin/sh #set -x work1=/tmp/ofl1.$$ work2=/tmp/ofl2.$$ work3=/tmp/ofl3.$$ sort_str="-k 5,6 -k 1,2 -k 6,7 -k 7,8" format_str="" trap "rm -f $work1 $work2 $work3" 0 1 2 3 15 # get the options set -- `getopt czd $*` if test $? != 0 then echo 'Usage: -c -z -d' exit 2 fi for i do case "$i" in -z) #sort by zine, (country, name, dest) sort_str="-k6,7 -k5,6 -k1,2 -k9,10" format_str="-z" shift;; -d) #sort by dest, (country, name, issue) sort_str="-k 9,10 -k 5,6 -k 1,2 -k 6,7" format_str="-d" shift;; -c) # source country format_str=$i; shift;; --) shift; break;; esac done flatten.pl order.dat > $work1 # extract the header grep -v "^Header:" $work1 > $work2; grep "^Header:" $work1 > $work3; mv $work2 $work1 # grep out the selection while [ $# -ne 0 ] do egrep $1 $work1 >$work2 mv $work2 $work1 shift done # sort sort -t\| $sort_str -o $work1 $work1 # put the header back cat $work3 $work1 > $work2; # print cat $work2 | prOrd.pl - $format_str