Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

script to compare files in a list with files in directory

Status
Not open for further replies.

cmeth3

Programmer
Dec 6, 2002
3
US
I'm fairly new to shell scripting. I need to create a script that will compare the files from a list of files to the files in a complex directory structure. First, I used 'ls -alR > filelist' to store the full 'long' descriptions of files within a complex directory structure. Then I need to use 'filelist' to compare files in the same directory structure in a different system. Any files in the complex directory structure (of the new system) not having the same file permissions and filename (upper, lower, or mixed case) from the filelist, must be changed according to the filelist. Does anyone have any ideas?
 
Hello,
Try this i am not confident that it is solution as required.
Any way i havenot tested it properly.#!/bin/ksh

#directory structure into filetestfile and load that load that file to test directory

#where you are running script and befor running this script

tmp_filelist=`cat ./filelist `

# you are in diferrent complex directory structure of differrent system

ls -alr> filesystem_under_differrent_directory_differrent_system
tmp_file_list_from_system=`cat ./filesystem_under_differrent_directory_differrent_system


for i in $tmp_filelist; do

grep $i $tmp_file_list_from_system
if [ $? == 0 ]; then
echo $i >> file_found_list
else
grep -i $i $file_list_from_system
if [ $? == 0 ]; then
echo $i >> file_found_case_incorrect_list
else
echo $i >> file_not_found_list
fi
fi
done


#The section which creates the restructure the dirctoryfor files which are found with

#casesensitive problems into one asin filetest.


tmp_file_found_case_incorrect_list=`cat file_found_case_incorrect_list`

for j in $tmp_file_found_case_incorrect_list;do
mkdir -p $j
done


Cheers
SANPDA
 
Hello sorry,

1.there is some misalligment in above post after #!/bin/ksh hit an anter

2.missing backquote after second cat operation


SANPDA

 
hello ,
I have done some mistakes as you see the correctedone

#!/bin/sh

#ls -alR > filelist in sample dirctory strcuture get initially contents of the

#directory structure into filetestfile and load that load that file to test directory

#where you are running script and befor running this script

tmp_filelist=`cat ./filelist `

# you are in diferrent complex directory structure of differrent system

ls -alr > filesystem_under_differrent_directory_differrent_system
tmp_file_list_from_system=`cat ./filesystem_under_differrent_directory_differrent_system`


for i in $tmp_filelist; do

grep $i $tmp_file_list_from_system
if [ $? == 0 ]; then
echo $i >> file_found_list
else
grep -i $i $tmp_file_list_from_system
if [ $? == 0 ]; then
echo $i >> file_found_case_incorrect_list
else
echo $i >> file_not_found_list
fi
fi
done


#The section which creates the restructure the dirctoryfor files which are found with

#casesensitive problems into one asin filetest.


tmp_file_found_case_incorrect_list=`cat file_found_case_incorrect_list`

for j in $tmp_file_found_case_incorrect_list;do
mkdir -p $j
done

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top