Help regarding effective usage of diff for comparing files


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Help regarding effective usage of diff for comparing files
# 1  
Old 05-20-2011
Error Help regarding effective usage of diff for comparing files

Help regarding effective usage of diff for comparing files

Hi All,

I have few doubts regarding best usage of diff command. I also have some questions with out put of diff command.


File1:
ABC
DEF

File2:
ABC
DEFAA

Code:
diff file1 file2
2c2 
<DEF
-----
>DEFAA

QUESTION:
What does this 2c2 signifies. I also see some times it as 2d5, i have googled regarding this but couldn't found any information regarding this. If some one can please tell me what it signifies, that will be of great help, preferably if some link to study this.

COMING TO MY MAIN PROBLEM:

Problem statement:

I want to dump non common lines when two files are diffed to new files. In case of above example two files should be generated
i.e. file1_new and file2_new that contains only "DEF" and "DEFAA" only (lines which are not common).

I also want to maintain the line number (original) of these files to be dumped in new files.


Thanks in advance,
Sarbjit

Last edited by sarbjit; 05-21-2011 at 03:18 AM.. Reason: code tags...
# 2  
Old 05-20-2011
Quote:
Problem statement:

I want to dump non common lines when two files are diffed to new files. In case of above example two files should be generated
i.e. file1_new and file2_new that contains only "DEF" and "DEFAA" only (lines which are not common).

I also want to maintain the line number (original) of these files to be dumped in new files.
Sorry I don't think that the "diff" command is suitable. The output of "diff" gives lines in context and will therefore output some lines which are not different. It also does not number the lines.

The requirement for the line number eliminates every unix utility I can think of.
We'd certainly need to be sure that these are unix format text files and know a lot more about the data structure. Programs to process differences are really only effective on sorted files which do not contain large numbers of identical data.
In this case sorting the data would appear to be out of the question because you want to maintain the order of the data.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Comparing two directories with diff

Hi all, I have 2 directories on two different servers. I am trying to find out what is missing from directory X and what is missing from directory Y. they should both have the same exact files in them. I understand some files may be missing from both directories on each server. I am not sure... (8 Replies)
Discussion started by: jeffs42885
8 Replies

2. Shell Programming and Scripting

Diff 3 files, but diff only their 2nd column

Guys i have 3 files, but i want to compare and diff only the 2nd column path=`/home/whois/doms` for i in `cat domain.tx` do whois $i| sed -n '/Registry Registrant ID:/,/Registrant Email:/p' > $path/$i.registrant whois $i| sed -n '/Registry Admin ID:/,/Admin Email:/p' > $path/$i.admin... (10 Replies)
Discussion started by: kenshinhimura
10 Replies

3. UNIX for Dummies Questions & Answers

Comparing lists when "diff" isn't sufficiently stringent

Greetings. I like to compare two lists of numbers, A.txt and B.txt, to see the numbers that are in B.txt but not in A.txt. I only need the "deletions" with reference to A.txt. Using the diff command doesn't work because it considers too many of the deletions just changes because they are a... (7 Replies)
Discussion started by: Twinklefingers
7 Replies

4. Shell Programming and Scripting

diff bw two files

Hi All, I have two files which look as below File1 serial="1" name="abc" type="employee" field="IT" serial="2" name="cde" type="intern" field="Marketing" serial="3" name="pqr" type="contractor" field="IT" serial="4" name="xyz" type="employee" field="Sales" File2 serial="1"... (3 Replies)
Discussion started by: grajp002
3 Replies

5. AIX

How to monitor the IBM AIX server for I/O usage,memory usage,CPU usage,network..?

How to monitor the IBM AIX server for I/O usage, memory usage, CPU usage, network usage, storage usage? (3 Replies)
Discussion started by: laknar
3 Replies

6. Shell Programming and Scripting

Diff b/w 2 files

Hi Masters, I have two files named file1 and file2. Both the files contains the same contents with some difference in comments,space.But no content change. I tried to find the diff between the two files to make sure that contents are same. For that i tried diff -ibw file1 file2 But... (1 Reply)
Discussion started by: ecearund
1 Replies

7. Linux

Using SQUID to reduce traffic usage in the office - how effective?

We are working in the office where about 5-6 machines have Internet access. We pay for each GB of traffic we consume and that's quite expensive. Almost no worker download files. Just surfing websites (including our corporate one that is located outside of local network thus we pay for accessing it... (5 Replies)
Discussion started by: FractalizeR
5 Replies

8. HP-UX

how can I find cpu usage memory usage swap usage and logical volume usage

how can I find cpu usage memory usage swap usage and I want to know CPU usage above X% and contiue Y times and memory usage above X % and contiue Y times my final destination is monitor process logical volume usage above X % and number of Logical voluage above can I not to... (3 Replies)
Discussion started by: alert0919
3 Replies

9. Shell Programming and Scripting

Find duplicates from multuple files with 2 diff types of files

I need to compare 2 diff type of files and find out the duplicate after comparing each types of files: Type 1 file name is like: file1.abc (the extension abc could any 3 characters but I can narrow it down or hardcode for 10/15 combinations). The other file is file1.bcd01abc (the extension... (2 Replies)
Discussion started by: ricky007
2 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