Question regarding the diff command


Login or Register for Dates, Times and to Reply

 
Thread Tools Search this Thread
# 1  
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  
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  
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  
Quote:
Originally Posted by Jazmania
How can I show whats just in the original file.
The diff command shows changes only.
# 5  
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  
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  
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 for Dates, Times and to Reply

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Test Your Knowledge in Computers #691
Difficulty: Medium
UnixWare is a Unix operating system originally released by Univel.
True or False?

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Help with diff command

Platform :Oracle Linux 6.4 Shell : bash In the below sample, although the lines in a.txt and b.txt are jumbled up, there is only one difference : b.txt has an extra line NETHERLANDS $ cat a.txt SPAIN NORTH KOREA PORTUGAL GERMANY SYRIA $ $ $ cat b.txt GERMANY NORTH KOREA SPAIN... (6 Replies)
Discussion started by: John K
6 Replies

2. 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

3. 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

4. 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

5. 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

6. 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

7. 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

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

Featured Tech Videos