[ale] UNIX Question
Jacob Langseth
jlangseth at esisys.com
Mon Nov 30 14:10:53 EST 1998
> 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"
> Does a method for determining this pop into your head?
Certainly not the most efficient method I'm sure, but
#!/bin/bash
# SMALL must have leading / trailing space
if [ "${SMALL##* }" != "" ]; then SMALL="${SMALL} "; fi
if [ "${SMALL%% *}" != "" ]; then SMALL=" ${SMALL}"; fi
# cycle through LARGE, prepare diff list
for item in $LARGE; do
if [ "${SMALL/ $item /}" == "$SMALL" ]; then
diff="$diff $item"
fi
done
# dump diffs
echo "differences = $diff"
#EOF#
For non-bash shells, ${SMALL/ $item /} can be
replaced with `echo "$SMALL" | sed "s/ $item //g"`
Jacob
More information about the Ale
mailing list