Compare File Differences in different directories


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Compare File Differences in different directories
# 1  
Old 02-08-2010
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.
Code:
diff -r "www.website/intranet" "website_2/intranet" | grep -i | tee FileDetailDiff

Test 2 - Works great.
Code:
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.
Code:
#!/bin/sh
find . -type f|grep .asp$ | while read file
do
   echo "$file"
done

here is the error i am getting:
Code:
$ 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.

Last edited by Scott; 02-09-2010 at 03:22 AM.. Reason: Please use code tags
# 2  
Old 02-09-2010
syntax for while loop to read a line is

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


Last edited by Scott; 02-09-2010 at 03:22 AM..
# 3  
Old 02-09-2010
HP-UX B.11.23 Performance Monitor tool ?

Is this application for HP-UX ?

Last edited by manijash; 02-09-2010 at 02:33 AM..
# 4  
Old 02-09-2010
I am running this on a windows box using cygwin to run the script.

I tried the following:

Code:
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:
Code:
$ 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:
Code:
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 Smilie

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

Code:
tr -d '\r' < your_file > newfile

Thanks for every ones help

Last edited by Franklin52; 02-09-2010 at 03:02 PM.. Reason: Please use code tags!
# 5  
Old 02-09-2010
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!:

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

cat mylist | while read line
do
echo "Next file is: $line"
done < $line
Code:
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

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Compare directories and copy differences (files) in a another directory

Hey im working on script that can compare 2 directory and check difference, then copy difference files in third diretory. here is the story: in folder one we have 12 subfolder and in each of them near 500 images hosted. 01 02 03 04 05 06 07 08 09 10 11 12 in folder 2 we have same subfolder... (2 Replies)
Discussion started by: nimafire
2 Replies

2. UNIX for Beginners Questions & Answers

Compare two big files for differences using Linux

Hello everybody Looking for help in comparing two files in Linux(files are big 800MB each). Example:- File1 has below data $ cat file1 5,6,3 2.1.4 1,1,1 8,9,1 File2 has below data $ cat file2 5,6,3 8,9,8 1,2,1 2,1,4 (8 Replies)
Discussion started by: shanul karim
8 Replies

3. Shell Programming and Scripting

Compare two big files for differences using Linux

Hello everybody Looking for help in comparing two files in Linux(files are big 800MB each). Example:- File1 has below data $ cat file1 5,6,3 2.1.4 1,1,1 8,9,1 File2 has below data $ cat file2 5,6,3 8,9,8 1,2,1 2,1,4 (1 Reply)
Discussion started by: shanul karim
1 Replies

4. Shell Programming and Scripting

Need to compare the two files and list out differences between the two

Hi, I need to compare the two files and list out difference between the two. Please assist. Best regards, Vishal (2 Replies)
Discussion started by: Vishal_dba
2 Replies

5. UNIX for Dummies Questions & Answers

Compare and merging the differences in text file

Hi i have gone through some sdiff command it shows the differences side by side and its really awesome file 1: this tool is for checking the differ merging with flower pots documentation file 2: this t ool is for checking the differ mergin g with flower pots documentation ... (27 Replies)
Discussion started by: rakeshkumar
27 Replies

6. Shell Programming and Scripting

Differences between 2 directories

Hi, I am trying to write a script under ksh to list all the differences between two directories. For example: # ls test1 test2 I need to compare all the files under between test1 & test2. When I do diff, it only compares the diectoires but it doesn't check inside. I did do... (3 Replies)
Discussion started by: samnyc
3 Replies

7. HP-UX

Compare 2 systems to find any differences

Hi there, I have 2 machines running HP-UX. One off these controllers is able to send mail and the other cannot. I have looked at all the settings that I know and coannot find any differences. Is there a way to audit the 2 machinces by pulling all the settings then compare any differences? ... (2 Replies)
Discussion started by: lodey
2 Replies

8. Shell Programming and Scripting

Compare two text files and Only show the differences

Hi experts, I'mvery new to shell scripting and learning it now currently i am having a problem which may look easy to u :) i have two files File 1: Start :Thu Nov 19 10:33:09 2009 ABCDGFSDJ.txt APDemoNew.ppt APDemoOutline.doc ARDemoNew.ppt ARDemoOutline.doc File 2: Start... (10 Replies)
Discussion started by: CelvinSaran
10 Replies

9. Shell Programming and Scripting

Compare File Names in Different Directories...

I do not know much about shell scripting and need to create a script and I am at a loss. If someone can help me, that would be great!! I have two directories: /dir1 /dir2 I need to get the sequence number which is part of the filename in /dir1 and delete all files in /dir2 that are... (4 Replies)
Discussion started by: stky13
4 Replies

10. UNIX for Dummies Questions & Answers

du -s -k differences between two identical directories

I tarred a directory from a linux server to a solaris server. When I do a du -s -k on the directory, I get almost 150k difference in the file sizes. If I do a ls | wc -l, it is the same. If I look at the size of the individual files, it is the same. I did an ls on the 2 directories and... (6 Replies)
Discussion started by: csgonan
6 Replies
Login or Register to Ask a Question