|
google site
|
|||||||
| Forums | Register | Blog | Man Pages | Forum Rules | Links | Albums | FAQ | Users | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
![]() |
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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 scottn; 02-09-2010 at 02:22 AM.. Reason: Please use code tags |
| Sponsored Links | ||
|
|
|
#2
|
|||
|
|||
|
syntax for while loop to read a line is Code:
while read line do .... .... done <$file Last edited by scottn; 02-09-2010 at 02:22 AM.. |
|
#3
|
|||
|
|||
|
HP-UX B.11.23 Performance Monitor tool ?
Is this application for HP-UX ?
Last edited by manijash; 02-09-2010 at 01:33 AM.. |
|
#4
|
|||
|
|||
|
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 ![]() 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 02:02 PM.. Reason: Please use code tags! |
|
#5
|
|||
|
|||
|
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:
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 |
| Sponsored Links | ||
|
|
![]() |
| Bookmarks |
| Tags |
| compare, directory, files |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Compare two text files and Only show the differences | CelvinSaran | Shell Programming and Scripting | 10 | 02-26-2010 04:56 AM |
| How to compare two directories... | Taranjeet Singh | Shell Programming and Scripting | 2 | 04-07-2009 02:20 PM |
| Compare File Names in Different Directories... | stky13 | Shell Programming and Scripting | 4 | 05-09-2008 04:36 PM |
| Compare 2 files for a single column and output differences | samit_9999 | UNIX for Dummies Questions & Answers | 1 | 04-23-2008 12:02 PM |
| du -s -k differences between two identical directories | csgonan | UNIX for Dummies Questions & Answers | 6 | 08-07-2007 10:04 AM |