LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   How to avoid some differences in Diff command (https://www.linuxquestions.org/questions/linux-general-1/how-to-avoid-some-differences-in-diff-command-544885/)

rajbal 04-10-2007 01:53 PM

How to avoid some differences in Diff command
 
Hi ,
I am trying to make the diff skip some of the differences which i know might appear.Is there a way to avoid displaying the selected difference in two file.I know there is a option "--ignore-matching-lines=" in the diff but that is useful to get rid of lines that are added or deleted.I want to avoid lines which are real difference.

Regards,
RAJESH

gilead 04-10-2007 05:38 PM

The --ignore-matching-lines= option checks changed lines as well as those added or deleted. However, the original and changed lines have to match the regular expression. From the man page:
Code:

      -I RE  --ignore-matching-lines=RE
              Ignore changes whose lines all match RE.

What this means is if you have the following file1:
Code:

line 1
line 2
line 3
line 4
line 5
line 6
line 7
line 8
line 9

And the following file2:
Code:

line 1
line added
line 2
line 3
line 4
line 6
line 7
line 8 changed
line 9

You get the following outputs:
Code:

$ diff file1 file2
1a2
> line added
5d5
< line 5
8c8
< line 8
---
> line 8 changed
$ diff --ignore-matching-lines='8.*' file1 file2
1a2
> line added
5d5
< line 5
$ diff --ignore-matching-lines='changed' file1 file2
1a2
> line added
5d5
< line 5
8c8
< line 8
---
> line 8 changed

It means that you have to construct your regular expression to catch both forms of the changed line (before and after)

rajbal 04-10-2007 05:59 PM

Hi Gilead,
Can you explain what you mean by before and after here?

Regards,
Raj

gilead 04-10-2007 11:28 PM

I was assuming that the files you were diff'ing were changed versions of one file. For example, the original file (the before file) had some changes made and was saved as the new file (the after file).

Or, in the case of individual lines in the file, the before line is the line the way it was in the original file. The after line is the line the way it is in the changed file.


All times are GMT -5. The time now is 12:10 AM.