![]() |
|
|
|||||||
| Home | Forums | Register | Rules & FAQ | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !! |
Other UNIX.COM Threads You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Comparing data in file with values in table | Mohit623 | Shell Programming and Scripting | 0 | 01-22-2008 04:57 AM |
| Comparing 2 list and deleting deuplicate entries | eltinator | Shell Programming and Scripting | 10 | 08-15-2007 10:35 AM |
| Problem comparing 2 files with lot of data | rafisha | Shell Programming and Scripting | 4 | 07-25-2007 04:56 PM |
| Comparing a distinct value in 1 list with another list | manualvin | Shell Programming and Scripting | 6 | 06-22-2004 03:42 AM |
| getting data list into a hash array | topcat8 | Shell Programming and Scripting | 5 | 03-09-2004 08:02 AM |
![]() |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
|||
|
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
Gianni added code tags for readability --oombera Last edited by oombera : 02-18-2004 at 06:11 PM. |
| Forum Sponsor | ||
|
|
|
|||
|
Thanks for your response. But doesn't the code just check 'mylist'?? It seems like it would always return 'found' to me.
Where is the comparison to the 'filelist'? I didn't know how the iteration should be handled here using ksh script. True that it can halt after finding one instance in filelist but it may still have to check the entire list, non? For example, the third file of 50 in mylist could be the 35th file listed in filelist...how do I handle the interation...I've only handle a single while read situation but not a dual case. Gianni. |
|
||||
|
The '-e' in the 'if' statement checks the current directory to see if the file exists. You do not need to build a data structure containing the 'ls' input. You can simply check the directory directly. In the example, what will happen is it will do the following:
if janfile.tar exists, then print found and exit if janfile.jar exists, then print found and exit if jan.rpt.Z exists, then print found and exit There is no reason to compare 'mylist' against every file in the directory. Suppose you have 1000 file in the directory and you only care if janfile.tar exists. Why would you want to compare it to the other 999 files when you can basically have the program asks if it exists or not without having to iterate through each filename? The for loop is looping through the values of mylist and "asking" if those files exist, it does not care about the other file that may or may not be in that directory. Hope that explains it. |
|
|||
|
Grazie Tio Tony!
Based on your suggestion, I was able to do what I wanted to do. I think my analogy to doing an 'ls' was throwing you off; however, your solution was fine for it. I wanted to simply my question - most of my questions posed here are not actual but similar to what I wanted to achieve. I was able to build upon your suggestions and now my scripts are working fine. Ciao! |
|||
| Google UNIX.COM |