- Save the script as
diff-search.pl - Make it executable:
chmod +x diff-search.pl - Optionally, move to your PATH:
sudo mv diff-search.pl /usr/local/bin/
./diff-search.pl --search "htmlEncode" files.diff./diff-search.pl --search "htmlEncode" --stats files.diff./diff-search.pl --search "htmlEncode" --output htmlEncode-patches.diff files.diff./diff-search.pl --search "ajxstringutil" --ignore-case files.diff./diff-search.pl --search "htmlEncode" --search "AjxStringUtil" files.diff./diff-search.pl --search "htmlEncode" --verbose --stats files.diffcat files.diff | ./diff-search.pl --search "htmlEncode"./diff-search.pl --search "htmlEncode" --dry-run files.diffWhen you run:
./diff-search.pl --search "htmlEncode" --stats files.diffYou'll get output like:
=== SEARCH STATISTICS ===
Search terms: htmlEncode
Case sensitive: true
Total files processed: 15
Files with matches: 5
Total hunks processed: 45
Hunks with matches: 8
Total matches found: 12
Files with matches:
+++ new/./opt/zimbra/jetty_base/webapps/zimbra/js/MailCore_all.js
+++ new/./opt/zimbra/jetty_base/webapps/zimbra/js/NewWindow_2_all.js
+++ new/./opt/zimbra/jetty_base/webapps/zimbra/js/Startup2_all.js
+++ new/./opt/zimbra/jetty_base/webapps/zimbra/js/Voicemail_all.js
+++ new/./opt/zimbra/jetty_base/webapps/zimbra/js/zimbraMail/calendar/view/ZmQuickReminderDialog.js
========================
[SUCCESS] Found matches in 8 hunks across 5 files
--- old/./opt/zimbra/jetty_base/webapps/zimbra/js/MailCore_all.js 2025-04-24 21:19:32.000000000 -0700
+++ new/./opt/zimbra/jetty_base/webapps/zimbra/js/MailCore_all.js 2025-06-11 06:56:46.000000000 -0700
@@ -8880,12 +8880,12 @@
var attendee = this._invite.getAttendees()[0];
var ptst = attendee && attendee.ptst;
if (ptst) {
- var names = [];
- var dispName = attendee.d || attendee.a;
- var sentBy = attendee.sentBy;
- var ptstStr = null;
- if (sentBy) names.push(attendee.sentBy);
- names.push(dispName);
+ var names = [];
+ var dispName = AjxStringUtil.htmlEncode(attendee.d || attendee.a);
+ var sentBy = AjxStringUtil.htmlEncode(attendee.sentBy);
+ var ptstStr = null;
+ if (sentBy) names.push(AjxStringUtil.htmlEncode(attendee.sentBy));
+ names.push(dispName);
subs.ptstIcon = ZmCalItem.getParticipationStatusIcon(ptst);
switch (ptst) {
case ZmCalBaseItem.PSTATUS_ACCEPT:
[... more hunks ...]
Once you have extracted the patches, you can apply them using:
patch -p0 < htmlEncode-patches.diffgit apply htmlEncode-patches.diff# Check if patch can be applied
git apply --check htmlEncode-patches.diff
# Apply if check passes
git apply htmlEncode-patches.diff./diff-search.pl --search "html.*Encode" --search "AjxStringUtil\.html" files.diff./diff-search.pl --search "calendar" --ignore-case --output calendar-changes.diff files.diff./diff-search.pl --search "htmlEncode" --search "encode" --search "escape" --stats files.diff| Option | Short | Description |
|---|---|---|
--search PATTERN |
-s |
Search pattern (required, can be used multiple times) |
--file FILE |
-f |
Input diff file (default: stdin) |
--output FILE |
-o |
Output file (default: stdout) |
--context LINES |
-c |
Context lines around matches (default: 3) |
--ignore-case |
-i |
Case insensitive search |
--stats |
-S |
Show search statistics |
--verbose |
-v |
Verbose output |
--dry-run |
-n |
Show what would be done |
--help |
-h |
Show help message |
- Always use
--statsfirst to understand what you're working with - Use
--dry-runto verify your search parameters before generating output - Save important patches to files using
--output - Test patches in a safe environment before applying to production
- Use version control to track your changes
- Combine with other tools like
grep,awk, orsedfor complex filtering
Find all XSS prevention changes:
./diff-search.pl --search "htmlEncode" --search "escape" --search "sanitize" --stats files.diffTrack specific feature changes:
./diff-search.pl --search "calendar" --search "appointment" --ignore-case files.diffExtract specific bug fix hunks:
./diff-search.pl --search "bug" --search "fix" --search "CVE" --ignore-case files.diffFind method rename patterns:
./diff-search.pl --search "oldMethodName" --search "newMethodName" files.diff