[ale] UNIX Question

Michelangelo Grigni mic at mathcs.emory.edu
Tue Dec 1 10:13:10 EST 1998


> From: Wandered Inn <esoteric at denali.atlnet.com>
> Stan.Hearn at ipst.edu wrote:
> > I've got two lists:
> > LARGE="aaa bbb ccc ddd eee fff ggg hhh iii jjj kkk"
> > SMALL="aaa ccc ddd eee fff ggg"
> > Solution: DIFF="bbb hhh iii jjj kkk"
> > ...  I know this is an easy problem for perl, but this piece
> > is part of a larger /bin/sh script.
> #!/usr/bin/perl -w

Long live /bin/sh:

LARGE="aaa bbb ccc ddd eee fff ggg hhh iii jjj kkk"
SMALL="aaa ccc ddd eee fff ggg"
DIFF=""
for tok in $LARGE
do
  case " $SMALL " in
  *" $tok "*) ;;
  *) case "$DIFF" in
     '') DIFF="$tok" ;;
     *) DIFF="$DIFF $tok" ;;
     esac ;;
  esac
done

Or a little shorter in /bin/ksh:

LARGE="aaa bbb ccc ddd eee fff ggg hhh iii jjj kkk"
SMALL="aaa ccc ddd eee fff ggg"
DIFF=""
for tok in $LARGE
do [[ " $SMALL " = *" $tok "* ]] || DIFF="${DIFF+$DIFF }$tok"
done






More information about the Ale mailing list