The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM



View Single Post in UNIX Forums - Click on the Thread or Permalink to View Entire Thread -->
  #1 (permalink)  
Old 03-03-2003
giannicello giannicello is offline
Registered User
 

Join Date: Sep 2001
Location: Phoenix
Posts: 76
Comparing data list...

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

Last edited by oombera; 02-18-2004 at 06:11 PM.
Forum Sponsor