1
diff cookies.old cookies.new
5c5
< One cup vanilla extract
---
> One teaspoon vanilla extract
7d6
< Six ounces chopped liver
21a22

Any flags/options can help me get rid of this 5c5, 7d6, 21a22 in output ? What does these characters mean exactly ?

nitins
  • 2,579
  • 15
  • 44
  • 68

4 Answers4

6

Those are the line numbers and the operation to change one to the other. "5c5" means "line five changed (replaced) to line five", "7d6" means "delete line seven", "21a22" means "add (append) line 22"

You can change the output format using options such as --context=NUM or --unified.

Here is some more information on output formats from the info file for diff.

This command would only show the lines that are different without showing the line number and modification type (it will also eliminate the "----" dividers):

diff cookies.old cookies.new | grep '^[<>]'
Dennis Williamson
  • 62,149
  • 16
  • 116
  • 151
1

http://www.linuxselfhelp.com/gnu/diffutils/html_chapter/diff_3.html

note: "Detailed Description of Normal Format"

Sirex
  • 5,499
  • 2
  • 33
  • 54
1

Sounds like you just want a more user-friendly diff output. The main reason diff is so percise is because it is used to generate patches. For more user friendly output I recommend:

[kbrandt@alpine: ~/scrap/diff] echo -e 'foo\nbar' > file1
[kbrandt@alpine: ~/scrap/diff] echo -e 'foo\nbaz' > file2
[kbrandt@alpine: ~/scrap/diff] diff -y file1 file2
foo                             foo
bar                               | baz
[kbrandt@alpine: ~/scrap/diff] colordiff -y file1 file2

Colordiff will give you the side by side output but with lines in different colors to give more emphasis to the differences.

Kyle Brandt
  • 83,619
  • 74
  • 305
  • 448
-1

Numbers are used to identify the offset of the file where the difference occurs.

Check diff man page or

http://ss64.com/bash/diff.html

http://en.wikipedia.org/wiki/Diff

lrosa
  • 1,687
  • 14
  • 15