Comparing data list...


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Comparing data list...
# 1  
Old 03-03-2003
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 10:11 PM..
# 2  
Old 03-04-2003
Since you are only concerned if at least 1 file exists this may work for you:
Code:
mylist="janfile.tar jarfile.jar jan.rpt.Z" 
for i in $mylist
do
   if [ -e $i ]
   then
     echo found $i   #or e-mail and halt
     exit 0
   fi
done

The -e just checks to see if the file exists. If it does, then the expression is true and the echo is run.

added code tags for readability --oombera

Last edited by oombera; 02-18-2004 at 10:11 PM..
# 3  
Old 03-04-2003
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.
# 4  
Old 03-05-2003
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.
# 5  
Old 03-06-2003
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!
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Comparing to 3 data

# cat list.txt server1 server2 server3 server4 # data to be compared of. #dns address 1.1.1.1 2.2.2.2 3.3.3.3 #for i in `cat list.txt` do grep dns $ i done (1 Reply)
Discussion started by: invinzin21
1 Replies

2. Shell Programming and Scripting

Comparing list of files

Hi All, I have a list of files and want to find the difference between each file if there is difference then i want the file name to be printed and log the duplicate files For example Size Filename 23 a1 23 a2 23 a3 45 a4 If i diff a1 and a2 and find... (3 Replies)
Discussion started by: wedng.bell
3 Replies

3. UNIX for Dummies Questions & Answers

Comparing lines of data

Total UNIX Rookie, but I'm learning. I have columns of integer data separated by spaces, and I'm using a Mac terminal. What I want to do: 1. Compare "line 1 column 2" (x) to "line 2 column 2" (y); is y-x>=100? 2. If yes, display difference and y's line number 3. If no, increment x and y by... (9 Replies)
Discussion started by: markymarkg123
9 Replies

4. Shell Programming and Scripting

Comparing the data in a 2 files

Hi Friends, I have a file 1 CREATE MULTISET TABLE TEYT_Q9_T.TEST ,NO FALLBACK , NO BEFORE JOURNAL, NO AFTER JOURNAL, CHECKSUM = DEFAULT, DEFAULT MERGEBLOCKRATIO ( XYZ DECIMAL(10,0), ABC VARCHAR(5) CHARACTER SET LATIN NOT CASESPECIFIC, PQR... (3 Replies)
Discussion started by: i150371485
3 Replies

5. Shell Programming and Scripting

Shell script for comparing data of tables

Hi, I have two databases with same tables on different servers.I need to check the data content in each table and if something is missing, should print that. I have a tool which takes the snapshot the table structure,index so on and compares with the other server tables snapshot. Now i need... (1 Reply)
Discussion started by: nessj
1 Replies

6. Shell Programming and Scripting

Extract data based on match against one column data from a long list data

My input file: data_5 Ali 422 2.00E-45 102/253 140/253 24 data_3 Abu 202 60.00E-45 12/23 140/23 28 data_1 Ahmad 256 7.00E-45 120/235 140/235 22 data_4 Aman 365 8.00E-45 15/65 140/65 20 data_10 Jones 869 9.00E-45 65/253 140/253 18... (12 Replies)
Discussion started by: patrick87
12 Replies

7. Shell Programming and Scripting

Comparing data inside file

Hi Everyone, I will try to explain my question please forgive my english here. I am looking for shell script or command that can compare data in the files. I have 50 files in one directory test1 test2 test3 ....so on. I want to compare data in each files with each other and output each... (4 Replies)
Discussion started by: email-lalit
4 Replies

8. Shell Programming and Scripting

Comparing data in file with values in table

Hi, I want to calculate the number of pipe delimiters in a file for all lines seperately. For eg:i have a file Project.txt Mohit|chawla|123|678 File1|File2|345|767|678 And my file contains many lines like this it shd give me the output as 4 5 or give me the output for all the... (0 Replies)
Discussion started by: Mohit623
0 Replies

9. Shell Programming and Scripting

Problem comparing 2 files with lot of data

Hello everyone, here's the scenario I have two files, each one has around 1,300,000 lines and each line has a column (phone numbers). I have to get the phones that are in file1 but not in file2. I can get these phones trough Oracle but my boss does not want that so he gave me the files with the... (4 Replies)
Discussion started by: rafisha
4 Replies

10. Shell Programming and Scripting

Comparing a distinct value in 1 list with another list

Hi all, I need to compare the contents of 2 directories where the file contents are similar and take out the filenames whose contents does not exist within the 2 directories. Directory1 1 2 3 4 Directory2 54 55 56 57 Does anyone has a script which can do this? At the end of... (6 Replies)
Discussion started by: manualvin
6 Replies
Login or Register to Ask a Question