Remove certain files from unfied diff

78 Views Asked by At

I have a patch to apply on legacy codebase. There are a lot of files named pom.xml is there, changes to which are to be skipped. How do I remove them from patch?

sed '/^diff --git .*pom.xml$/,/^diff --git/d'

removes a one extra line at the end (which is nedeed for further processing).

I probably need a solution to delete lines between two patterns including first pattern and excluding second one. I'm limited to MSYS, so only Windows commands, sed and mawk are accessible.

Here is an example of input. There are three entries there, second one is to be removed.

diff --git a/core/contexts/org.eclipse.rcptt.ctx.debug/META-INF/MANIFEST.MF b/core/contexts/org.eclipse.rcptt.ctx.debug/META-INF/MANIFEST.MF
index a02c3f0..b74197f 100644
--- a/core/contexts/org.eclipse.rcptt.ctx.debug/META-INF/MANIFEST.MF
+++ b/core/contexts/org.eclipse.rcptt.ctx.debug/META-INF/MANIFEST.MF
@@ -2,13 +2,13 @@ Manifest-Version: 1.0
 Bundle-ManifestVersion: 2
 Bundle-Name: Q7 Debug
 Bundle-SymbolicName: org.eclipse.rcptt.ctx.debug;singleton:=true
-Bundle-Version: 1.5.0.qualifier
+Bundle-Version: 1.5.3.qualifier
 Bundle-ClassPath: .
 Bundle-Vendor: Eclipse RCP Testing Tool Project
 Bundle-Localization: plugin
 Bundle-RequiredExecutionEnvironment: JavaSE-1.6
 Require-Bundle: org.eclipse.core.runtime,
- org.eclipse.rcptt.core;bundle-version="[1.5.0,1.6.0)";visibility:=reexport
+ org.eclipse.rcptt.core;bundle-version="[1.5.3,1.6.0)";visibility:=reexport
 Bundle-ActivationPolicy: lazy
 Export-Package: org.eclipse.rcptt.debug,
  org.eclipse.rcptt.debug.impl,
diff --git a/core/contexts/org.eclipse.rcptt.ctx.debug/pom.xml b/core/contexts/org.eclipse.rcptt.ctx.debug/pom.xml
index e12f814..e18b46a 100644
--- a/core/contexts/org.eclipse.rcptt.ctx.debug/pom.xml
+++ b/core/contexts/org.eclipse.rcptt.ctx.debug/pom.xml
@@ -4,10 +4,10 @@
   <parent>
     <artifactId>rcptt.core.contexts</artifactId>
     <groupId>org.eclipse.rcptt</groupId>
-    <version>1.5.0-SNAPSHOT</version>
+    <version>1.5.3-SNAPSHOT</version>
   </parent>
   <groupId>org.eclipse.rcptt</groupId>
   <artifactId>org.eclipse.rcptt.ctx.debug</artifactId>
-  <version>1.5.0-SNAPSHOT</version>
+  <version>1.5.3-SNAPSHOT</version>
   <packaging>eclipse-plugin</packaging>
 </project>
diff --git a/core/contexts/org.eclipse.rcptt.ctx.extensions/META-INF/MANIFEST.MF b/core/contexts/org.eclipse.rcptt.ctx.extensions/META-INF/MANIFEST.MF
index 88ccb8b..b8c1308 100644
--- a/core/contexts/org.eclipse.rcptt.ctx.extensions/META-INF/MANIFEST.MF
+++ b/core/contexts/org.eclipse.rcptt.ctx.extensions/META-INF/MANIFEST.MF
@@ -2,7 +2,7 @@ Manifest-Version: 1.0
 Bundle-ManifestVersion: 2
 Bundle-Name: Q7 Context Extensions
 Bundle-SymbolicName: org.eclipse.rcptt.ctx.extensions;singleton:=true
-Bundle-Version: 1.5.0.qualifier
+Bundle-Version: 1.5.3.qualifier
 Bundle-Activator: org.eclipse.rcptt.ctx.extensions.ContextExtensionsPlugin
 Bundle-Vendor: Eclipse RCP Testing Tool Project
 Require-Bundle: org.eclipse.core.runtime,

All solutions I've found so far either remove both starting and trailing lines with patterns or none of them.

1

There are 1 best solutions below

0
On

Finally, a working solution:

awk '
  /^diff --git/ {skip = 0}
  /^diff --git .*pom.xml$/ { skip = 1}
  {if (!skip) print $0}
' 

This was not a sed's job, probably.