Two folder comparison


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Two folder comparison
# 8  
Old 04-23-2008
Oh, and if your diff is that different (sic) from mine, perhaps you want to check that its output is as expected before you plunge ahead and run it on all your files.

Try something quick in the /tmp directory:

Code:
vnix$ cd /tmp
vnix$ mkdir foo bar
vnix$ echo one >foo/one
vnix$ echo one >bar/one
vnix$ echo two >foo/too
vnix$ echo three >foo/three
vnix$ echo four >bar/three
vnix$ diff -r foo bar
diff -r foo/three bar/three
1c1
< three
---
> four
Only in foo: too
vnix$

The boldfaced lines are the ones grep will look for. If your output looks different, you need to adapt.
# 9  
Old 04-23-2008
Quote:
Originally Posted by ragavhere
Testing and testing1 are the directories containing the files which have to be compared.

This script is going to be automated and will be a generic one and will be run by using a java code.so i cant create symbolic links each and every time i need to compare two directories. can the code be modified to suit this purpose?
If the directories you want to compare will always exist side by side in the directory tree, then yes, it's trivial. If not, some additional gyrations are required, but it's not extremely complicated either.

Code:
#!/bin/sh

case $# in 2);; *) echo "syntax: $0 dir1 dir2" >&2; exit 2;; esac

dir1="$1"
dir2="$2"

base1=`basename "$dir1"`
base2=`basename "$dir2"`

# note: predictable temp names are a security problem!
# FIXME: use something fancier here
# Also, won't work if dir1 or dir2 is directly in /tmp ...
mkdir /tmp/$base1 /tmp/$base2

# clean out temporary directories if interrupted
trap 'rm -rf /tmp/$base1 /tmp/$base2' 0
trap 'exit 127' 1 2 3 5 15

while read d t; do
  for f in "$d"/*; do
    test -d "$f" || continue
    egrep -v '^(HDR|FTR)' "$f" | sort >"$t"/${f#"$d"}
  done
done <<HERE
$dir1 $base1
$dir2 $base2
HERE

diff -r /tmp/$base1 /tmp/$base2 | egrep '^(Only in |diff )'

As you can see, the additional motions are rather unsightly but not altogether very complex.

Are you getting paid to solve this problem?
# 10  
Old 04-23-2008
Two folder comparison

Hi era,

Ya. I am paid for this. I tried to create two variables containing the path containg the files. For this variable i am creating a symbolic link.

but the thing is I am getting stuck here in creating the temporary folder.

a=/gdw/shared/qa2/dev/scripts_regr_test/design3/extract_comparison/testing/
b=/gdw/shared/qa2/dev/scripts_regr_test/design3/extract_comparison/testing1/
ln -s $a dir1
ln -s $b dir2
c=/gdw/shared/qa2/dev/scripts_regr_test/design3/extract_comparison/
mkdir $c/tmp/dir1 $c/tmp/dir2
for file in dir1/* dir2/*; do
test -d "$file" && continue # skip if it's a directory
egrep -v '^(HDR|FTR)' "$file" | sort >/tmp/"$file"
done
diff -r $c/tmp/dir1 $c/tmp/dir2 | egrep '^(diff|Only in )'

Can anything be done on this code itself?
# 11  
Old 04-23-2008
You need the $c before /tmp after the sort also.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Delete oldest folder based on folder named as date

Hi, I have a script doing backup to synology server, the script create new folder each day with the date as being folder name i.e. 2018-07-30. Just before creating the new folder I want the script to find the oldest folder from the list and delete it including its content. for example... (3 Replies)
Discussion started by: humble_learner
3 Replies

2. Shell Programming and Scripting

Request for Shell script to move files from Subfolder to Parent folder and delete sub folder

Hi Team, I am new to shell script and there is a requirement where files should be moved from Subfolder to parent folder. Eg: parent folder --> /Interface/data/test/IN Sub folder -->/Interface/data/test/IN/Invoice20180607233338 Subfolder will be always with timestamp... (6 Replies)
Discussion started by: srivarun15
6 Replies

3. Shell Programming and Scripting

Shell scripting for moving folder specific files into target directory of that country folder.

I need help to write shell script to copy files from one server to another server. Source Directory UAE(inside i have another folder Misc with files inside UAE folder).I have to copy this to another server UAE folder( Files should be copied to UAE folder and Misc files should be copied in target... (3 Replies)
Discussion started by: naresh2389
3 Replies

4. Shell Programming and Scripting

do a full comparison of folder contents in script

Hello everyone.... I have a small issue here at work and I am trying to script out a way to automate a fix for it. I have a small number of users (I work in a 1:1 with 6,000 macbooks) that aren't really managed in my deployment. They are managed with a few policies, but the policies are broken... (2 Replies)
Discussion started by: tlarkin
2 Replies

5. Shell Programming and Scripting

File Management: How do I move all JPGS in a folder structure to a single folder?

This is the file structure: DESKTOP/Root of Photo Folders/Folder1qweqwasdfsd/*jpg DESKTOP/Root of Photo Folders/Folder2asdasdasd/*jpg DESKTOP/Root of Photo Folders/Folder3asdadfhgasdf/*jpg DESKTOP/Root of Photo Folders/Folder4qwetwdfsdfg/*jpg DESKTOP/Root of Photo... (4 Replies)
Discussion started by: guptaxpn
4 Replies

6. UNIX for Dummies Questions & Answers

Jar/Tar to a diffent folder/same folder w/ filename

Hi, I want to extract myfile.war to a folder which is in the same folder with war file.I did this as normal: jar -xvf myfile.war But it exploded all the content of file to the same level folder instead of that I was expecting to create a folder called myfile. This works with tar: ... (0 Replies)
Discussion started by: reis3k
0 Replies

7. Windows & DOS: Issues & Discussions

How can I upload a zip folder on a unix path from my windows folder?

Hello, I am an amature at UNIX commands and functionality. Please could you all assist me by replying to my below mentioned querry : How can I upload a zip folder on a unix path from my windows folder? Thanks guys Cheers (2 Replies)
Discussion started by: ajit.yadav83
2 Replies

8. UNIX for Advanced & Expert Users

Auto copy for files from folder to folder upon instant writing

Hello all, I'm trying to accomplish that if a file gets written to folder /path/to/a/ it gets automatically copied into /path/to/b/ the moment its get written. I thought of writing a shell script and cron it that every X amount of minutes it copies these files over but this will not help me... (2 Replies)
Discussion started by: Bashar
2 Replies

9. Shell Programming and Scripting

Parse the .txt file for folder name and FTP to the corrsponding folder.

Oracle procedure create files on UNIX folder on a regular basis. I need to FTP files onto windows server and place the files, based on their name, in the corresponding folders. File name is as follows: ccyymmddfoldernamefile.txt; Folder Name length could be of any size; however, the prefix and... (3 Replies)
Discussion started by: MeganP
3 Replies
Login or Register to Ask a Question