Skip to main content

Search and replace tool that outputs a diff compatible with patch

Project description

Description

sar.py is a simple search and replace script that outputs a valid diff file for review and later apply with patch.

Usage

$ ./sar.py unified_diff megasuper_diff sar.py

Searching for 'unified_diff' and replacing to 'megasuper_diff'

Processing file sar.py ... MATCH FOUND
Index: sar.py
================================================================================
--- sar.py (original)
+++ sar.py (modified)
@@ -88,7 +88,7 @@
             debug("MATCH FOUND\n")
             print "Index:", filename
             print "=" * 80
-            diff = ''.join(list(difflib.unified_diff(orig.splitlines(1),
+            diff = ''.join(list(difflib.megasuper_diff(orig.splitlines(1),
                                                      res.splitlines(1),
                                                      filename + " (original)",
                                                      filename + " (modified)")))

Licence

This script is released under the MIT licence

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sar-tool-1.0.1.tar.gz (1.8 kB view hashes)

Uploaded source

Built Distribution

sar-tool-1.0.1.linux-x86_64.tar.gz (1.7 kB view hashes)

Uploaded any

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page