bug-gnu-utils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to exclude certain hunk types (added, changed, deleted) from dif


From: Alexander Kriegisch
Subject: Re: How to exclude certain hunk types (added, changed, deleted) from diff
Date: Thu, 27 Sep 2007 20:24:21 +0200
User-agent: Thunderbird 2.0.0.6 (Windows/20070728)

Hi there!

Just because I was bugging you I want to return a favour and present my
solution. Well, I have known how to work with sed and regexes for a long
time, but never got into that cryptic sed buffer stuff. Even if I would
have succeeded implementing a filter that way, probably in three months
I would not have understood my own script anymore.

So I finally decided to do what has been overdue for years: I peeked
into an awk tutorial and read just enough to non-elegantly but
effectively do what I want: filter
  - added
  - deleted
  - changed
hunks from uni-diffs. The solution is not very elegant, quick & dirty
and probably not perfect, but it works well for my purposes. There are
three awk scripts, each one capable filtering out one type of hunk,
leaving the rest unchanged. Chain the scripts via pipes in order to
narrow down the output. Example:

# Remove added hunks
cat my-diff.patch | no-added.awk

# Remove added and deleted hunks, leaving only changed ones
cat my-diff.patch | no-added.awk | no-deleted.awk

# Remove all hunks, leaving only diff headers and comments
cat my-diff.patch | no-added.awk | no-deleted.awk | no-changed.awk

Regards
--
Alexander Kriegisch

>>> I have a special case here in which I am getting huge diff 
>>> outputs, but am interested only in deleted and changed hunks, not
>>> added hunks.
>> 
>> Have you looked into diffutils, which comes with the program 
>> filterdiff?
> 
> Just for the protocol: You probably mean patchutils. Thanks for 
> pointing me there, but neither filterdiff nor any other utility from 
> that package manage to do what I described.

#!/usr/bin/awk -f

/^[^-+ ]/ { filter = 0 }
/^(\+\+\+|---) / { filter = 0 }
/^@@ -[0-9]+,0 / { filter = 1 }
filter == 0 { print $0 }
#!/usr/bin/awk -f

/^[^-+ ]/ { filter = 0 }
/^(\+\+\+|---) / { filter = 0 }
/^@@ .* @@$/ { filter = 1 }
/^@@ .*,0.* @@$/ { filter = 0 }
filter == 0 { print $0 }
#!/usr/bin/awk -f

/^[^-+ ]/ { filter = 0 }
/^(\+\+\+|---) / { filter = 0 }
/^@@ -[0-9]+.* \+[0-9]+,0 @@$/ { filter = 1 }
filter == 0 { print $0 }

reply via email to

[Prev in Thread] Current Thread [Next in Thread]