Help with diff output


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help with diff output
# 1  
Old 10-16-2013
Help with diff output

I am running diff between two directories dir1 and dir2.

diff --exclude --recursive --brief -b dir1 dir2

The output of the above command is

Code:
Files dir1/java/abc/bcd/abc9991.java and dir2/java/abc/bcd/abc9991.java differ
Files dir1/java/abc/bcd/abc9933.java and dir2/java/abc/bcd/abc9933.java differ
Only in dir2/ora/dpc: g025_abc.dpc
Only in dir2/ora/dpc: gc_cvb_jrp_1650_abc.dpc
Only in dir2/ora/dpc: gc_k_jrp_502901690_abc.dpc
Files dir1/ora/ps/abc_bcda640921_bcd.sp and dir2/ora/ps/abc_bcda640921_bcd.sp differ
Files dir1/ora/ps/cvg_fgh640931_drv_msd.sp and dir2/ora/sp/cvg_fgh640931_drv_msd.sp differ


Want to extract file names from the diff output based on file extensions(have over 6 extensions in the subdirectories .java,.dpc,.cvg, and so on)

and delete all the files in dir2 except these in the diff output.


example: from the above diff output I want to extract files
Code:
abc9991.java
gc_cvb_jrp_1650_abc.dpc
gc_k_jrp_502901690_abc.dpc
abc_bcda640921_bcd.sp
cvg_fgh640931_drv_msd.sp   from dir2 and delete rest of the files from dir2.

Tried using the cut command but too many sub directories inside and each time the position has to change.

Last edited by Scott; 10-17-2013 at 12:36 PM.. Reason: More code tags
# 2  
Old 10-16-2013
Why are abc9933.java and g025_abc.dpc excluded?
# 3  
Old 10-16-2013
example: from the above diff output I want to extract files

Code:
abc9991.java
abc9933.java
g025_abc.dpc
gc_cvb_jrp_1650_abc.dpc
gc_k_jrp_502901690_abc.dpc
abc_bcda640921_bcd.sp
cvg_fgh640931_drv_msd.sp

from dir2 and delete rest of the files.
.

---------- Post updated at 04:35 PM ---------- Previous update was at 04:34 PM ----------

@CarloM: My bad I missed them
# 4  
Old 10-16-2013
The aim being to delete duplicate files from dir2 and sub-directories?
# 5  
Old 10-16-2013
Correct. I only need newer and changed files in dir2.
# 6  
Old 10-16-2013
If your diff supports -s (report identical files):
Code:
diff -s --exclude --recursive --brief -b dir1 dir2 | awk '/identical$/ {print $4}' | xargs echo rm

echo is just for error checking, remove it if the output looks right.

EDIT: If not then you could do something a bit more complicated:
Code:
diff <(diff --exclude --recursive --brief -b dir1 dir2 | awk '/^Only/ {printf "%s/%s\n", $3, $5} /differ$/ {print $4}' FS=" |:" | sort) <(find dir2 -type f|sort) | awk '{print $2}' | xargs echo rm


Last edited by CarloM; 10-16-2013 at 06:24 PM..
# 7  
Old 10-17-2013
Tried this initially. Did not work. The output was rm.

Code:
diff -s --exclude --recursive --brief -b dir1 dir2 | awk '/identical$/ {print $4}' | xargs echo rm

Then tried this it showed everything in dir2 as different and when I put the rm command at the end it deleted all the files in dir2.

Code:
diff <(diff --exclude --recursive --brief -b dir1 dir2 | awk '/^Only/ {printf "%s/%s\n", $3, $5} /differ$/ {print $4}' FS=" |:" | sort) <(find dir2 -type f|sort) | awk '{print $2}' | xargs echo rm

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Output formatting for diff -y

Hi, I wasn't sure whether to post this in the dummies or expert section, here's what I'm trying to do, but I suspect I'm missing the boat and should perhaps be using some of diff's builtin output functionality. diff -yb --suppress-common-lines file1.js file2.js >> ~/results.txt When I... (5 Replies)
Discussion started by: Buckaroo Banzai
5 Replies

2. UNIX for Dummies Questions & Answers

What does this diff output mean?

35d34 < What does that mean in diff? (3 Replies)
Discussion started by: glev2005
3 Replies

3. Shell Programming and Scripting

Processing diff output

How to get diff to not print the chevrons and the dashes? In this case the differences are all single line differences. Also the first few lines don't matter. How to get the output to always exclude the first few lines? Thanks! (1 Reply)
Discussion started by: stevensw
1 Replies

4. Shell Programming and Scripting

Tweaking the output of diff

hello everyone, I am trying to compare two files and have the result in a new files. When I used diff I am getting the header, '<' and '>' in my result which I don't want to have it in my output file. :wall: opt/sam/input: diff file1.txt file2.txt 1,20d0 < 16,ZA, < ZJ,08, < Z7,03, Any... (1 Reply)
Discussion started by: siteregsam
1 Replies

5. Shell Programming and Scripting

diff output next to each other

I have two files to compare, but diff output doesn't give me decent output I want. The portion of the two files are shown below. file 1) Authorize <1> Transaction Database Slave 3 <1> CPM HTTP Proxy Server <1> SSP (TDB Server) <1> CPM Application Authorization <7> CPM Script... (5 Replies)
Discussion started by: Daniel Gate
5 Replies

6. Shell Programming and Scripting

Format diff output

I need to compare two directories with tab separated files. I'm using diff to do this. diff output doesn't identify which column values are different, it just tells which lines are different. Is there any way to format diff output. Thanks f1.txt 210 998877 phone 9981128209 add 111 nw st.... (2 Replies)
Discussion started by: blackjack101
2 Replies

7. Shell Programming and Scripting

Formatting the output from diff

Hi, i need to display the mismatches from two files.The output what is get is the entire rows which mismatch from file 1 are displayed first and the corresponding rows from file 2 are displayed below it. Sample output: From Test Run 1 - The row count of file2.txt is 23 From Test Run 1 -... (9 Replies)
Discussion started by: ragavhere
9 Replies

8. Shell Programming and Scripting

Is there a way to limit DIFF output

Hello is there a way to limit the number of lines output by the DIFF command? I tried -C 200 ect and -c but it continues to print out the whole huge file. Reason needed is i'm trying to do alot of DIFFs on a long list of files and would like to only get back an indicator which files are... (2 Replies)
Discussion started by: bobk544
2 Replies

9. UNIX for Dummies Questions & Answers

diff output

I have two CSV files and I would like to create a third CSV file containing the differences between the two. I understand the diff command can be used to list differences between two files. My problem is that when I pipe the output into a third CSV file, the line numbers and other formatting... (3 Replies)
Discussion started by: paulp
3 Replies

10. Shell Programming and Scripting

diff 2 files; output diff's to 3rd file

Hello, I want to compare two files. All records in file 2 that are not in file 1 should be output to file 3. For example: file 1 123 1234 123456 file 2 123 2345 23456 file 3 should have 2345 23456 I have looked at diff, bdiff, cmp, comm, diff3 without any luck! (2 Replies)
Discussion started by: blt123
2 Replies
Login or Register to Ask a Question