Compare File Differences in different directories

Hello,

I am new to scripting and have been trying to compare two different directories, but with all the same file names in each directory for file changes. I have been doing it in baby steps and have been doing pretty good, but I have hit a few snags. Test 1 and Test 2 work great, but my ultimate end goal is for each file to have a "difference" file instead of one "difference" file. Also, I am using cygwin to do this. I am comparing two identical websites for changes in code.

Test 1 - Works great.

diff -r "www.website/intranet" "website_2/intranet" | grep -i | tee FileDetailDiff

Test 2 - Works great.

diff -r -q "www.website/intranet" "website_2/intranet" | tee FileNameDiff

My last step / tutorial for me is to loop through all the files and this is where i keep getting errors.
This does not work. I figure once i get this working i can add the code in to check for file differences.

#!/bin/sh
find . -type f|grep .asp$ | while read file
do
   echo "$file"
done

here is the error i am getting:

$ sh textdiff4.sh
textdiff4.sh: line 5: syntax error near unexpected token `done'
textdiff4.sh: line 5: `done'

For the life of me i cannot figure out what is wrong. Any help would be appreciated.

Thanks for taking the time to read this.

syntax for while loop to read a line is

while read line 
do
....
....
done <$file

Is this application for HP-UX ?

I am running this on a windows box using cygwin to run the script.

I tried the following:

find . -type f -name "*asp" > mylist

cat mylist | while read line
do
echo "Next file is: $line"
done < $line

I am getting the following errors:

$ sh textdiff4.sh
textdiff4.sh: line 7: $'\r': command not found
textdiff4.sh: line 11: syntax error near unexpected token `done'
textdiff4.sh: line 11: `done < $line'

I can do:

find . -type f -name "*asp" > mylist
cat mylist

and it executes just fine. For some reason it has to be some ID10T error on my part on why i can't get a simple loop to work :stuck_out_tongue:

regards

---------- Post updated at 12:41 PM ---------- Previous update was at 11:48 AM ----------

Ok I finally figured it out. I am using notepad++ to create the files, I guess it is adding carriage return line feeds. I ran this command and it removed the carriage return line feeds and it now works

tr -d '\r' < your_file > newfile

Thanks for every ones help

Ignoring the MSDOS/unix line terminator issue which you have resolved.

This script is faulty because the input should either come from an inward redirect "<" or from a pipe "while read" but not both!:

It would be better as:

find . -type f -name "*asp" while read line
do
          echo "Next file is: $line"
done

Or alternatively in the POSIX manner.

find . -type f -name "*asp" > mylist

while read line
do
            echo "Next file is: $line"
done < mylist