Diff with Sections/Headers

diff -U 9999 file_a file_b | tail -n +3 | grep -P "^(\ Header|\-|\+)"
Maybe very limited in its applicability but could be of use at times.
Sample Output
 Header1
-   y
+   f
 Header2
-   C
+   D
 Header3
-   3
+   1

0
By: nnutter
2011-09-21 21:33:40

These Might Interest You

  • Uses the formatting of a man page to show an outline of its headers and sub-headers. Show Sample Output


    2
    man ls | egrep "^([A-Z]| [A-Z])"
    bartonski · 2013-01-09 17:12:03 0
  • This form is used in patches, svn, git etc. And I've created an alias for it: alias diff='diff -Naur --strip-trailing-cr' The latter option is especially useful, when somebody in team works in Windows; could be also used in commands like svn diff --diff-cmd 'diff --strip-trailing-cr'... Show Sample Output


    3
    diff -Naur --strip-trailing-cr
    ruslan · 2011-02-10 14:32:42 0
  • get subversion diff output without distracting whitespace changes. good for when you are cleaning up code to make sure you didn't change anything important. also useful when working with old code, or someone else's code.


    0
    svn diff --diff-cmd diff -x -uw /path/to/file
    katylava · 2009-02-10 20:39:54 1
  • When running a long `diff -r` over folders, this simulates a "verbose" mode where you can see where diff is in the tree. Replace $file with the first part of the path being compared.


    2
    lsof -c diff -o -r1 | grep $file
    d0g · 2014-01-29 18:35:28 1

What do you think?

Any thoughts on this command? Does it work on your machine? Can you do the same thing with only 14 characters?

You must be signed in to comment.

What's this?

commandlinefu.com is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.

Share Your Commands



Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.

» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10

Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for: