Find with in loops and then difference


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Find with in loops and then difference
# 1  
Old 07-24-2012
Java Find with in loops and then difference

Hi All,

Please find my problem below:
I have a file at two different nodes dev and test

1st find> find /u/dev/local/abc -name ab.dat
--Since this file can be in several sub directories
2nd find> find /u/test/local/abc -name ab.dat

I find my 1st find result and do compare with 2nd find result. Have to see the diffrence in the two file.

I am doing a find on the following way since I have file ab.dat in many sub directories of /u/dev/local/abc (/u/dev/local/abc/p1,/u/dev/local/abc/p2/p01 etc). I need to search for prence of thsi file in each sub directory and then compare it with subsequent test file.

The above find gives me list of all the ab.dat file with their sub-directories. I do not want to use an external file to store the result and then pick one by one and do diff in dev and test directories. Is there way to do it through loops.Smilie

Find in dev --> get the first dev/d1/ab.dat then look for the corresponding test directory test/d1/ab.dat and then do diff ans say there was difference the go on to search next in loop and print the list of the path/ab.dat file having difference.

Thanks,
Varun
# 2  
Old 07-24-2012
Quote:
I need to search for prence of thsi file in each sub directory and then compare it with subsequent test file.
By "subsequent" do you mean corresponding?
This User Gave Thanks to methyl For This Post:
# 3  
Old 07-24-2012
Do you need to compare each file with every other file, or just with the one found after it?

Code:
find /u/dev/local/abc -name ab.dat | while read LINE
do
        if [ ! -z "$PREV" ]
        then
                echo "Comparing $LINE with $PREV"
        fi

        PREV="$LINE"
done

This User Gave Thanks to Corona688 For This Post:
# 4  
Old 07-24-2012
This is what my requirement is

@Methyl/Corona688: Yes
1st find> find /u/dev/local/abc -name ab.dat
results:
/u/dev/local/abc/pqr/ab.dat
/u/dev/local/abc/pqr/xyz/ab.dat
/u/dev/local/abc/mno/ab.dat
2nd find> find /u/test/local/abc -name ab.dat
results:
/u/test/local/abc/pqr/ab.dat
/u/test/local/abc/pqr/xyz/ab.dat
/u/test/local/abc/mno/ab.dat

So need to find compare(see the difference) row by row,and display the diff. SO
/u/dev/local/abc/pqr/ab.dat needs to compared with
/u/test/local/abc/pqr/ab.dat

/u/dev/local/abc/pqr/xyz/ab.dat needs to compared with
/u/test/local/abc/pqr/xyz/ab.dat

and so on.
Please help.Smilie

Thanks
# 5  
Old 07-24-2012
Oh, I see. You want to compare files in /dev/ with their corresponding files in /test/.

Code:
find /u/dev/local/abc /u/test/local/abc -name ab.dat |
        sed 's#/u/dev/##g;s#/u/test/##g' | sort -u |
while read LINE
do
        diff /u/dev/"$LINE" /u/test/"$LINE"
done

This User Gave Thanks to Corona688 For This Post:
# 6  
Old 07-25-2012
Print the file names

Hi,

I applied the following code so it gives me diffrences for all the file in one go. what would be the command that says there was difference between the two files. The message should be:

"/test/xyz/ab.dat and /dev/xyz/ab.dat has difference."<next line>
<The difference in two files>
"/test/pqr/ab.dat and /dev/pqr/ab.dat has difference."<next line>
<The difference files>

This message can be also redirected to a file.

Thanks,
Varun
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Difference between WHILE and FOR loops

This might be a simple question, but I can't find the answer out there anywhere. I'm trying to write a loop to SSH to a server for me to then copy/paste some commands in. Once I'm done, I type 'exit' and the loop should then automatically SSH to the next server in line. The 'dbs_group' file... (6 Replies)
Discussion started by: mccmjc
6 Replies

2. Shell Programming and Scripting

To find Difference

Hi Friends, I need to find the difference between two files , File_1 contained 4 columns, and File_2 contained 4 columns, I need to find the difference using 1st column, Or need to find the difference using 3st column, (6 Replies)
Discussion started by: Shenbaga.d
6 Replies

3. UNIX for Dummies Questions & Answers

Find time difference

I have a file wich contains time formats and i need to get the time difference TIME1 TIME2 =============== =================== 20120624192555.6Z 20120624204006.5Z which means first date 2012/6/24 19:25:55,second date 2012/6/24 20:40:06 so when i get the time... (23 Replies)
Discussion started by: wnaguib
23 Replies

4. Shell Programming and Scripting

To find difference between two files on a whole

Hi, The requirement is to compare two files that has single column of records each. Comparison is to happen on a whole and not line by line. File1.txt 314589929 315611087 304924413 315989094 301171509 302984393 315609549 314593632 File2.txt 315611087 304924413 315989094 (2 Replies)
Discussion started by: anandek
2 Replies

5. UNIX for Advanced & Expert Users

Find difference between 2 files

I have 2 files as follows. file1.txt <cell>123</cell> <cell>345</cell> file2.txt <cell>123</cell> <cell>456</cell> out out should be output.txt <cell>456></cell> How do we achieve this> The difference betwenn the two files should be wirtten to the output file.. ... (2 Replies)
Discussion started by: kanthrajgowda
2 Replies

6. UNIX for Dummies Questions & Answers

Find difference between two files

I have two files as below File1: a b c d File2: a b When i find the difference the output would be c&d.. How can i get my requirement...pls help... Many thanks in advance (10 Replies)
Discussion started by: jagadish_gaddam
10 Replies

7. UNIX for Dummies Questions & Answers

Find difference in two files

Hola, Tengo un texto texto1.txt con el siguiente contenido: Malaga Cadiz Sevilla Hola Y otro .txt texto2.txt con: Malaga Cadiz Sevilla Cordoba Huelva quiero obtener en otro .txt la diferencia entre estos dos archivos: (14 Replies)
Discussion started by: danietepa
14 Replies

8. Emergency UNIX and Linux Support

to find difference between two files

I have a file which gets appended with records daily..for eg. 1st day of the month i get 9 records ,2nd day 9 records .....till the last day in the month...the no of records may vary...i store the previous days file in a variable oldfile=PATH/previousdaysfile....i store the current days file in a... (6 Replies)
Discussion started by: ganesh_248
6 Replies

9. UNIX for Advanced & Expert Users

find command loops in a sun Solaris 8 cluster

It has happended twice the past 3 months. The find command which is the standard part of unix accounting script "dodisk", which searches directories to find out how much disk space a user has used. On a particular cluster of 6 servers, several file systems, the find command has twice used all... (2 Replies)
Discussion started by: scottman
2 Replies

10. UNIX for Dummies Questions & Answers

Difference between locate and find

I was wondering what the difference was between the two commands, I understand that locate won't search for files with certain permissions set. Are there any others? Thanks (1 Reply)
Discussion started by: camerja1
1 Replies
Login or Register to Ask a Question