Unix Script to compare two files


 
Thread Tools Search this Thread
# 8  
It's enough if you just say cat /usr/lpp/web-data/mfg/nct/file-data/nctilllist.dat.

If you're still seeing the error, insert set -x in a new line after the hashbang line (#! /bin/bash) to debug the shell script. Check where you're seeing the error.
# 9  
Hellow ,

Last week when i ran this same script it was working .Today I tried running the same script its not working

I/p
Code:
nctilllist.dat
 
09000290031292.JPG
09000290031291.JPG
DP000695084811.JPG
DP000696084811.JPG
DP000697084811.JPG
DP000698084811.JPG
DP000699084811.JPG

Script i used

Code:
#!/bin/bash  -xv                                                        
echo "Start Time : " $(date +%m-%d.%H.%M.%S)                            
echo "*************************"                                        
tdate=$(date +_%m%d_%H%M%S)                                             
while read x                                                            
do                                                                      
    if [ -e /usr/lpp/web-data/mfg/nct/file-data/purgeDocs/$x ]          
    then                                                                
    echo "$x already present in purgedocs. Moving to next entry in nctilllist.dat"
    continue                                                            
    fi                                                                  
    if [ -e /usr/lpp/web-data/mfg/nct/file-data/$x ]                    
    then                                                                
    cp /usr/lpp/web-data/mfg/nct/file-data/$x /usr/lpp/web-data/mfg/nct/file-data/purgeDocs/
    else                                                                
    echo "$x already not found purgedocs. Moving to next entry in nctilllist.dat"
    fi                                                                  
done < /usr/lpp/web-data/mfg/nct/file-data/nctilllist.dat
echo "done"                               
echo "End Time : " $(date +%m-%d.%H.%M.%S)

O/p im getting is

Code:
Start Time :  02-11.12.17.38  
*************************     
done                          
End Time :  02-11.12.17.38

I dont see any data copied to purgeDocs

Any suggestion on this?

Last edited by methyl; 02-12-2012 at 07:22 PM.. Reason: more code tags
# 10  
Hi Gayathri,

Do your input contains an empty line as first line?

Last edited by pandeesh; 02-11-2012 at 02:21 PM..
# 11  
No , its not having any empty lines
# 12  
Hi Gayathri,

It's working fine for me.
see my results:
Code:
pandeeswaran@ubuntu:~$ cat compare_file.sh
#!/bin/bash  -xv                                                        
echo "Start Time : " $(date +%m-%d.%H.%M.%S)                            
echo "*************************"                                        
tdate=$(date +_%m%d_%H%M%S)                                             
while read x                                                            
do                                                                      
    if [ -e /training/$x ]          
    then                                                                
    echo "$x already present in purgedocs. Moving to next entry in nctilllist.dat"
    continue                                                            
    fi                                                                  
    if [ -e $x ]                    
    then                                                                
    cp $x "training/"
    else                                                                
    echo "$x already not found purgedocs. Moving to next entry in nctilllist.dat"
    fi                                                                  
done < nctilllist.dat
echo "done"                               
echo "End Time : " $(date +%m-%d.%H.%M.%S)
pandeeswaran@ubuntu:~$ bash compare_file.sh
Start Time :  02-12.03.57.27
*************************
done
End Time :  02-12.03.57.27
pandeeswaran@ubuntu:~$ cd training
pandeeswaran@ubuntu:~/training$ ls -l 1.txt 2.txt 3.txt 4.txt
-rw-rw-r-- 1 pandeeswaran pandeeswaran 0 2012-02-12 03:57 1.txt
-rw-rw-r-- 1 pandeeswaran pandeeswaran 0 2012-02-12 03:57 2.txt
-rw-rw-r-- 1 pandeeswaran pandeeswaran 0 2012-02-12 03:57 3.txt
-rw-rw-r-- 1 pandeeswaran pandeeswaran 0 2012-02-12 03:57 4.txt
pandeeswaran@ubuntu:~/training$

The files are getting copied.

Please let me know, if you need any more information.

Thanks
# 13  
(original bad post removed)

Quote:
cp /usr/lpp/web-data/mfg/nct/file-data/$x /usr/lpp/web-data/mfg/nct/file-data/purgeDocs/
Suggest you put an "echo" before this line so you know when it has executed.


Quick check whether these files exist:
Code:
cat /usr/lpp/web-data/mfg/nct/file-data/nctilllist.dat | while read filename
do
       if [ -e "${filename}" ]
       then
             ls -lad "${fileanme}"
       fi
done


Last edited by methyl; 02-12-2012 at 07:52 PM.. Reason: total rewrite (twice).
 

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to compare multiple files in UNIX?

Hi, I have below query related to multiple file comparing I have four files i want to compare it and contents of one file will not be presence in 3other files and if any content found then it will print the execution. Can you please help me how to achieve it. (2 Replies)
Discussion started by: soumyamihp
2 Replies

2. Shell Programming and Scripting

Compare two files in UNIX

I have requirement to compare two files in unix. Below are the sample files. File1: cn=test123,cn=bobgroup,dc=ind,dc=com cn=bob123,cn=bobgroup,dc=ind,dc=com cn=test13,cn=bobgroup,dc=ind,dc=com cn=est12,cn=bobgroup,dc=ind,dc=com cn=st123,cn=bobgroup,dc=ind,dc=com File2... (1 Reply)
Discussion started by: babu92
1 Replies

3. Shell Programming and Scripting

Compare files using Unix scripting

I have a file containing the below data obtained after running a diff command > abc 10 < abc 15 > xyz 02 <xyz 05 ..... Does anyone know how i can obtain output like : previous value of abc is 10 and present value is 15 similarly for all the comparisons in the text file (10 Replies)
Discussion started by: amithpatrick1
10 Replies

4. Shell Programming and Scripting

Compare two files in UNIX

Hi, I have two files File1 Contents: abc dcf sdc File2 Contents: dcf sdc erg Now my program should return the contents existing in File1 but not in File2. In this case output shoud be "abc" as abc is not available in File 2. It should not return "erg" by saying it is... (4 Replies)
Discussion started by: forums123456
4 Replies

5. Shell Programming and Scripting

Compare two files in unix

Hi Gurus I need your kind help sorting the below query I have two text files File1.txt ID Name Address 101 Srinath BBB 102 Sidharth CCC File2.txt ID Name Address 102 Siddharth DDD 103 Suman EEE Now the requirement is if the second file has... (0 Replies)
Discussion started by: Pratik4891
0 Replies

6. UNIX for Advanced & Expert Users

How to compare two files using UNIX?

I have two files which have primary key(s) for each row. I need to compare both the files and produce the output in the following format. Primary key(s),file1 value,file2 value. Both the input files will be comma separated files. I have accomplished this using perl, but it is... (6 Replies)
Discussion started by: gpsridhar
6 Replies

7. UNIX for Dummies Questions & Answers

how can i unix compare two files??

how can i unix compare two files?? var1 = 6499 7328 6351 7583 7573 var2 = 6499 7328 6351 7583 7777 i did: diff $var1 $var2 and i got the output: 1c1 < 6499 7328 6351 7583 7573 --- > 6499 7328 6351 7583 7777 what can i do with it? and what does it tell me?? how can i knoe that... (2 Replies)
Discussion started by: nirnir26
2 Replies

8. Shell Programming and Scripting

how to compare a two files in unix server.

Hi Friends, I have a requirement like i have two files in diffrent locations. i want to compare these two files, if both the files are same i want to return "0" else return 1. Please help me on this. Thanks sreenu. (3 Replies)
Discussion started by: sreenu80
3 Replies

9. UNIX for Dummies Questions & Answers

Unix Compare Files

Hi, I need to compare 2 files based on the first field in each file and output the differences to a new file. example File 1 and File 2 both have first field as Number ie: File 1 1252652355 1859553322 1778899562 File 2 1252652355 1859553322 So I would expect File 3 to... (2 Replies)
Discussion started by: Lagre1
2 Replies

10. UNIX for Advanced & Expert Users

UNIX; Compare two files

Hi Guys, Requirement: Want to compare two files, if the the content of both files is same then show "Good result" else Show "Bad Result" I am using the following logic if( cmp -s a b = 0 ) then echo "Good result" else echo "Bad result" exit 0 fi But this is... (1 Reply)
Discussion started by: abhishek3598
1 Replies

Featured Tech Videos