Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Search Forums:



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 !!

Reply    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 02-03-2012
Registered User
 

Join Date: Feb 2012
Posts: 9
Thanks: 1
Thanked 0 Times in 0 Posts
Unix Script to compare two files

Hello,

I have a dat file nctilllist.dat which will be present in the directory path
"/usr/lpp/web-data/mfg/nct/file-data/nctilllist.dat"

nctillist.dat will have reference to files like DP100001.jpg,DP10002.PDF,DP100003.doc

on the path /usr/lpp/web-data/mfg/nct/file-data will have original contents of files
DP100001.jpg,DP10002.PDF,DP100003.doc

I want to write a script to open the file nctillist.dat and read the file and compare them whether any matching file name is present in the link /usr/lpp/web-data/mfg/nct/file-data

ex: open nctillist ,read first name DP100001.jpg compare any similar name is present in the path /usr/lpp/web-data/mfg/nct/file-data ,
if yes move the original file in path /usr/lpp/web-data/mfg/nct/file-data to /usr/lpp/web-data/mfg/nct/file-data\purgedocs.

can anyone suggest how to write a script for this scenario.

Thanks
Sponsored Links
    #2  
Old 02-03-2012
balajesuri's Avatar
#! /bin/bash
 

Join Date: Apr 2009
Location: India
Posts: 1,021
Thanks: 9
Thanked 285 Times in 277 Posts

Code:
#! /bin/bash

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 not found in file-data. Moving to next entry in nctilllist.dat."
    fi
done < /usr/lpp/web-data/mfg/nct/file-data/nctilllist.dat

The Following User Says Thank You to balajesuri For This Useful Post:
gayathrivm (02-04-2012)
Sponsored Links
    #3  
Old 02-04-2012
Registered User
 

Join Date: Feb 2012
Posts: 9
Thanks: 1
Thanked 0 Times in 0 Posts
Thank you so much !! Its working

---------- Post updated at 10:48 AM ---------- Previous update was at 10:45 AM ----------

I have one more question , I invoke this script through a Mainframe job . When I run through Mainframe its saying the following error
/usr/lpp/web-data/mfg/nct/file-data/nctill_tar.sh 1: FSUM7729 missing closing "'"…

But when i run through putty its working as expected.

Any idea on this?
    #4  
Old 02-04-2012
balajesuri's Avatar
#! /bin/bash
 

Join Date: Apr 2009
Location: India
Posts: 1,021
Thanks: 9
Thanked 285 Times in 277 Posts
I don't understand when you say mainframe job.
1. Is it a part of a larger script?
2. As the error suggests, have you missed out on a closing quote somewhere?
Sponsored Links
    #5  
Old 02-05-2012
Registered User
 

Join Date: Feb 2012
Posts: 9
Thanks: 1
Thanked 0 Times in 0 Posts
Im basically a mainframe developer ,we have a mainframe pgm where we give all the path details to run the script from a mainframe pgm.

When i try running the script through mainframe pgm its giving the above error , but when run paste the same code in putty its working fine.

script i used

#!/bin/bash
cat {"/usr/lpp/web-data/mfg/nct/file-data/nctilllist.dat"}
while read x
do
if [ -e /usr/lpp/web-data/mfg/nct/file-data/purgeDocs/$x ]
then
echo "File already present in purgedocs. Continuing to next file."
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 not found in file-data. Moving to next entry in nctilllist.dat."
fi
done < /usr/lpp/web-data/mfg/nct/file-data/nctilllist.dat

Thanks
Sponsored Links
    #6  
Old 02-05-2012
balajesuri's Avatar
#! /bin/bash
 

Join Date: Apr 2009
Location: India
Posts: 1,021
Thanks: 9
Thanked 285 Times in 277 Posts
cat {"/usr/lpp/web-data/mfg/nct/file-data/nctilllist.dat"} => This doesn't appear to be valid. What're you trying to achieve?
Sponsored Links
    #7  
Old 02-05-2012
Registered User
 

Join Date: Feb 2012
Posts: 9
Thanks: 1
Thanked 0 Times in 0 Posts
ex:
/usr/lpp/web-data/mfg/nct/file-data/nctilllist.dat will have
DP10001.jpg
DP10002.pdf
DP10003.xls

/usr/lpp/web-data/mfg/nct/file-data/ will have
DP10001.jpg
DP10002.pdf
DP10003.xls

compare
/usr/lpp/web-data/mfg/nct/file-data/nctilllist.dat
/usr/lpp/web-data/mfg/nct/file-data/

if matching move the file from
/usr/lpp/web-data/mfg/nct/file-data/
/usr/lpp/web-data/mfg/nct/file-data/purgedocs

in the above case all the three files will be moved to
/usr/lpp/web-data/mfg/nct/file-data/purgedocs
since both has the same files.

Im listing the file nctillist.dat with that CAT cmd

let me know if im worng

Thanks
Sponsored Links
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
How to compare two files using UNIX? gpsridhar UNIX for Advanced & Expert Users 6 10-22-2010 03:19 AM
how can i unix compare two files?? nirnir26 UNIX for Dummies Questions & Answers 2 11-19-2009 06:52 AM
Unix Compare Files Lagre1 UNIX for Dummies Questions & Answers 2 12-11-2008 01:19 PM
how to compare all files in one unix box has been to copied to another unix box sravanreddym Shell Programming and Scripting 9 07-03-2008 11:43 AM
UNIX; Compare two files abhishek3598 UNIX for Advanced & Expert Users 1 11-06-2007 05:52 PM



All times are GMT -4. The time now is 03:39 AM.