Question regarding the diff command


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Question regarding the diff command
# 1  
Old 01-26-2010
Question regarding the diff command

When using the diff command how do you determine what is in one file and not the other or what are in both but slightly different..

Basically i have two files. One file contains the contents of an rcode folder on our Production box, the other contains the contents of an rcode folder on a Q1 box.. I've used awk on this files so that they just contain the file size and file name. e.g.
7615 prodquery.r
6875 prod_bclient_startup.r
5293 pendout.r
3839 pendevnt-f100.r

I've done a test run of this but but i can't work out from the diff output what is in one file but not the other or what is in both but slightly different.. ie file size.. how does the diff output showthese? Using korn shell if that makes a difference..
# 2  
Old 01-26-2010
The diff command displays a different version of lines that are found when comparing two files. The < character precedes lines from the first file and > precedes lines from the second file.

(Peek and O'Reilly, Unix Power Tools, O'Reilly and Ass, 1993 p 507)
# 3  
Old 01-26-2010
ok,
I've finally figured out that the diff output shows d – a line was deleted,
c – a line was changed & a – a line was added but it also gives the line numbers either side.

How can I show whats just in the original file. I'm guess that would be the lines with < and the d character but how can I just output the lines that contain these?
# 4  
Old 01-26-2010
Quote:
Originally Posted by Jazmania
How can I show whats just in the original file.
The diff command shows changes only.
# 5  
Old 01-26-2010
If you can sort both input files the "comm" or "sdiff" commands are worth a look.

Personally I'd compare the output from "cksum" to decide if two files were exactly the same.
# 6  
Old 01-26-2010
Quote:
Originally Posted by Jazmania
ok,
I've finally figured out that the diff output shows d - a line was deleted,
c - a line was changed & a - a line was added but it also gives the line numbers either side.

How can I show whats just in the original file. I'm guess that would be the lines with < and the d character but how can I just output the lines that contain these?
How about
Code:
diff file1 file2 | grep "^<"

# 7  
Old 01-27-2010
Quote:
Originally Posted by linuxpenguin
How about
Code:
diff file1 file2 | grep "^<"

Thanks, grep is the best solution.. Some times the easiest thing to do is the least obvious..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

One-way diff command?

Hello, I am trying to find the different files between multiple directories in Linux, here is a small assumption of what is inside the directories dir1 dir2 dir3 1.txt 1.txt 1.txt 2.txt 3.txt 3.txt 5.txt 4.txt 5.txt 6.txt 7.txt 8.txt I am using the following... (4 Replies)
Discussion started by: Error404
4 Replies

2. UNIX for Dummies Questions & Answers

Diff with exceptions Question

So I'm currently developing an automated test system and I'm verifying my results by running a set of baselined data through and comparing the output (which is in a txt file) to a baseline results file. So of course I'm just using the diff command. Unfortunately each time I run the test there are 2... (3 Replies)
Discussion started by: Smitty0881
3 Replies

3. UNIX for Dummies Questions & Answers

Re:using the diff command

Hi Guys I have a situation where I would like to use the diff command but I would like to see "number" of differences and than send it through and if statement and than view the difference if greater than 1. Eg. diff file1 file2 > than gives the "number" and I than say - if number >1... (3 Replies)
Discussion started by: Prega
3 Replies

4. Shell Programming and Scripting

Question concerning DIFF

Hey, I am running a linux shell script containing some php. I want to be able to do a DIFF on two files...if the files are identical, set an exit status of 0, and if they are different, set an exit status of 1. I have been looking long and hard on how to do this, but I don't think that I... (3 Replies)
Discussion started by: behrk2
3 Replies

5. Shell Programming and Scripting

diff command help

Hi all diff file1 file 2 command will give us op of diff between two file. But it aslo give its position and sign "<" or ">". I dont want position and sign in op. Only diff of content should be come as op. Kindly help me for this. Regards Jaydeep (1 Reply)
Discussion started by: jaydeep_sadaria
1 Replies

6. UNIX for Dummies Questions & Answers

diff command

Is there any option for the diff command (or maybe an entirely different command) that will give you only the text that differs between two files? When I use diff file1 file2, if any text on that line differs from one file to the next it'll print out the entire line. I'd like to see only the text... (2 Replies)
Discussion started by: red baron
2 Replies

7. AIX

diff command

hello i've two files. how i get the diff between the two files to new file. thanks best regards ariec (3 Replies)
Discussion started by: ariec
3 Replies

8. Shell Programming and Scripting

need help in diff command :

i have 2 file named test1,test2 contents of test1: 1 2 3 --------------------------- contents of test2: 1 2 3 4 5 -------------------------------------------------------- my desired o/p should be: diff test2 test1 4 (5 Replies)
Discussion started by: ali560045
5 Replies

9. Shell Programming and Scripting

diff command

All, How to exclude a directory while diff execution? For ex: To exclude file which we don't want to see diff, we have -x <filename>. Thanks in advance (1 Reply)
Discussion started by: Vichu
1 Replies

10. UNIX for Dummies Questions & Answers

diff command

Hi, I have 2 files i would like to have a DIFF command: 1.Marks differences between files or 2.Mentions just the differences Thanks :) (7 Replies)
Discussion started by: gilead29
7 Replies
Login or Register to Ask a Question