Most efficient but sort files first
diff $1 $2 | grep "^<" | sed 's/< //'
#!/bin/bash
#Get original internal field separator
ORIGIFS=$IFS
#set original internal field separator to end-of-line
IFS=`echo -en "\n\b"`
for i in `cat $1`
do
MYFOUND="NO"
for y in `cat $2`
do
if [[ "$i" == "$y" ]]
then
MYFOUND="YES"
break
fi
done
if [[ "$MYFOUND" == "NO" ]]
then
echo $i
fi
done
#set original internal field separator back to original
IFS=$ORIGIFS
or with arrays
#!/bin/bash
IFS=`echo -en "\n\b"`
myfile1=( $( < $1 ) )
myfile2=( $( < $2 ) )
for i in ${myfile1[[@]]}
do
MYFOUND="NO"
for y in ${myfile2[[@]]}
do
if [[ "$i" == "$y" ]]
then
MYFOUND="YES"
break
fi
done
if [[ "$MYFOUND" == "NO" ]]
then
echo $i
fi
done