I have a list of files that I want to compare to another list of files, how do I do that?
The first list will be my known list and hard coded, for example:
mylist="janfile.tar jarfile.jar jan.rpt.Z" etc.
The second list will be found by doing an 'ls' piped to a file:
ls > filelist.dat
I want to compare the list of files in 'mylist' to 'filelist.dat' and only send an email/warning if these files exist...any easy way to do that?
I tried searching the forum for this and found some ideas..but it doesn't seem to work and also, for me 'mylist' is going to be more than the results of 'filelist.dat' so this is probably reversed but I don't know how to tackle it.
Code:
exec < $HOME/filelist.dat
IFS=' '
while read afile ; do
#Not sure if below syntax will work:
for each in $mylist; do
IFS=' '
if [[ $afile == $mylist ]]; then
#Send warning.
else
#No warning.
fi
done
done
For me, as long as ONE item in mylist (assume 50 files)is found in filelist.dat (about 30 files) I want to halt and warn the user.
Gianni
added code tags for readability --oombera