I have a folder A which contains files 1,2,3... I also have a file xyz under a diff folder B containg the entries 1,2,3...
I am trying to compare and delete the nonexisting ones from xyz using the below code:
QFILE=/B/xyz
cd A
ls -1 > /tmp/file1
for fname in `cat $QFILE`
do
if [ -f /A/$fname ]
then
echo "Nothing to do\n"
else
sed /$fname/d $QFILE > /tmp/file2
mv /tmp/file2 $QFILE
fi
done
but this is emptying the whole xyz file rather than just deleting the mismatching entry. pls suggest a mechanism to achieve this.