|
Search Forums:
|
|||||||
| Forums | Register | Forum Rules | Linux and Unix Links | Man Pages | Albums | FAQ | Users | Calendar | 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 !! |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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
|
||||
|
||||
|
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
|
|||
|
|||
|
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
|
||||
|
||||
|
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
|
|||
|
|||
|
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
|
||||
|
||||
|
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
|
|||
|
|||
|
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 | ||
|
|
![]() |
| Thread Tools | Search this Thread |
| 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 |
|
|