Hi All,
I have a 2 path, one with oldfile path in which has several sub folders,each sub folders contains a config file(basically text file), likewise there will be another newfile path which will have sub folders, each sub folders contains a config file.
Need to read files from oldfile path sub folders and from newfile path sub folders and do sdiff command on those 2 files ie,
sdiff /oldfile path/sub folderA/fileA.txt /newfile path/sub folderA/fileA.txt |egrep '>|<|\|' > folderA_fileA_result.txt
but before using sdiff, need to sort the both the files ie,
sort /oldfile path/sub folderA/fileA.txt > fileA.txt
sort /newfile path/sub folderA/fileA.txt > fileA.txt
problem is not sure how search for same sub folder name from both oldfile path and newfile , if foldername matched then basically need to do below :
a. First use sort command to sort the content of each files
b. Compare files using sdiff command and save the sdiff result file in output folder
c. Need to archive the result files with some versioning, so that when there is new config files, then it has compare the oldfiles from archived folder with new files
Note : All the config files is basic text files having several lines.
---------- Post updated 27-03-13 at 09:29 AM ---------- Previous update was 26-03-13 at 03:50 PM ----------
ok, i tired comparing same file names from 2 different directories but am getting the below error, even though i have kept the same file in both folders. Am not sure how to skip . and .. file check
# Check the number of input parameters. If two parameters are given go ahead, else exit
if [ $# -eq 2 ]
then
OLDFILESDIR=$1
NEWFILESDIR=$2
else
echo "Usage: script.sh oldfilesdir newfilesdir"
exit
fi
# Validate from_directory
if [ ! -d "${OLDFILESDIR}" ]
then
echo "Directory ${OLDFILESDIR} does not exist!!"
exit
fi
# Validate to_directory
if [ ! -d "${NEWFILESDIR}" ]
then
echo "Directory ${NEWFILESDIR} does not exist!!"
exit
fi
cd ${OLDFILESDIR}
#for i in `find . -type f`
for i in `find . -name '*.txt'`
do
if [ ! -f ${NEWFILESDIR}/$i ]
then
echo "Same filename doesn't found in ${OLDFILESDIR}/$i and in ${NEWFILESDIR}/$i"
else
echo "Same filename found in ${OLDFILESDIR}/$i and in ${NEWFILESDIR}/$i"
sort ${OLDFILESDIR}/$i
sort ${NEWFILESDIR}/$i
sdiff ${OLDFILESDIR}/$i ${NEWFILESDIR}/$i |egrep '>|<|\|' > resultfile.txt
fi
done
Error:
Same filename doesn't found in oldfiles/./tcp.txt and in newfile/./tcp.txt
---------- Post updated at 09:30 AM ---------- Previous update was at 09:29 AM ----------
ok, i tired comparing same file names from 2 different directories but am getting the below error, even though i have kept the same file in both folders. Am not sure how to skip . and .. file check
# Check the number of input parameters. If two parameters are given go ahead, else exit
if [ $# -eq 2 ]
then
OLDFILESDIR=$1
NEWFILESDIR=$2
else
echo "Usage: script.sh oldfilesdir newfilesdir"
exit
fi
# Validate from_directory
if [ ! -d "${OLDFILESDIR}" ]
then
echo "Directory ${OLDFILESDIR} does not exist!!"
exit
fi
# Validate to_directory
if [ ! -d "${NEWFILESDIR}" ]
then
echo "Directory ${NEWFILESDIR} does not exist!!"
exit
fi
cd ${OLDFILESDIR}
#for i in `find . -type f`
for i in `find . -name '*.txt'`
do
if [ ! -f ${NEWFILESDIR}/$i ]
then
echo "Same filename doesn't found in ${OLDFILESDIR}/$i and in ${NEWFILESDIR}/$i"
else
echo "Same filename found in ${OLDFILESDIR}/$i and in ${NEWFILESDIR}/$i"
sort ${OLDFILESDIR}/$i
sort ${NEWFILESDIR}/$i
sdiff ${OLDFILESDIR}/$i ${NEWFILESDIR}/$i |egrep '>|<|\|' > resultfile.txt
fi
done
Error:
Same filename doesn't found in oldfiles/./tcp.txt and in newfile/./tcp.txt