Hi All,
am very new to perl, I have to shell script which compares 2 files line by line and get the difference (am using sdiff command)
Basically, i have to write perl script
a. takes 2 filepath as arguments while running the main script
b. search the sub folder on each path and find same filename
(note: sub folders in both path will have same name and as well same filename *.txt inside)
3. If samefile found, then do
a. sort both the file
b. do line by line comparision
c. generate the resultfile for each. Result file should have only :
different line in one file or either way
completely different line in both
basically sdiff output structure,
results/lines from both file side by side
am very new to perl, I have to shell script which compares 2 files line by line and get the difference (am using sdiff command)
Code:
#!/bin/bash # cmp_dir - program to compare two directories # Check for required arguments if [ $# -ne 2 ]; then echo "usage: $0 directory_1 directory_2" 1>&2 exit 1 fi # Make sure both arguments are directories if [ ! -d $1 ]; then echo "$1 is not a directory!" 1>&2 exit 1 fi if [ ! -d $2 ]; then echo "$2 is not a directory!" 1>&2 exit 1 fi # Process each file in directory_1, comparing it to directory_2 find $1/ -name '*.txt' -print | while read src do #for filename in $1/*.txt; do #echo $filename fn=$(basename "$filename") if [ -f "$filename" ]; then #if [ ! -f "$2/$fn" ]; then #echo "$fn is missing from $2" #missing=$((missing + 1)) #fi sort $filename #echo $filename sort $2/$fn #echo $2/$fn sdiff $filename $2/$fn | egrep '>|<|\|' > resultfile.txt fi #done done echo "File comparision done, please see resultfile"
a. takes 2 filepath as arguments while running the main script
b. search the sub folder on each path and find same filename
(note: sub folders in both path will have same name and as well same filename *.txt inside)
3. If samefile found, then do
a. sort both the file
b. do line by line comparision
c. generate the resultfile for each. Result file should have only :
different line in one file or either way
completely different line in both
basically sdiff output structure,
results/lines from both file side by side
Comment