Monday, 19 August 2013

How to stop a sed script if finding two start patterns before an end pattern?

How to stop a sed script if finding two start patterns before an end pattern?

I need to find all revisions in a subversion dump that have changes to
pom.xml.
I'm using svndumptool to successfully print the revisions, and then sed to
filter those findings.
I'm able to match the revision number as the start, but I need to be able
to throw this away if I find a second matching start before I find a stop.
Here is the command I'm using:
svnDumpTool =~/path/to/svndumptool.py
target=specificSvn.dump
# use svndumptool to read the svnlog from target to stdin |
# sed then matches start -r[0-9], such as -r103, ends on pom.xml
# then redirects stdout > to a log file for this target
$svnDumpTool log $target -v | sed -n '/r[0-9]/,/pom.xml/p' > $target.log
Considering a log of something like this:
-r0 | ... | ...
Changed paths:
none; initialization of the repo - not my match
-r1 | ... | ...
Changed paths:
... not my matches here
--------
-r2 | ... | ...
Changed paths:
... nor here
--------
-r3 | ... | ...
Changed paths:
Pom.xml
--------
-r4 | ... | ...
Changed paths:
Pom.xml
--------
-r5 | ... | ...
Changed paths:
... changes may or may not be here
--------
Here are the results.
On the first pass, I get more than I want:
I'll get a match on start of -r0,
A match on end of pom.xml from -r3,
Which prints all from start to stop, including -r0, -r1 & -r2:
-r0 | ... | ...
Changed paths:
none; initialization of the repo - not my match
-r1 | ... | ...
Changed paths:
... not my matches here
--------
-r2 | ... | ...
Changed paths:
... nor here
--------
-r3 | ... | ...
Changed paths:
Pom.xml
On the second pass, I get exactly what I want:
I'll get a match on start of -r4,
A match on end of pom.xml from -r4:
-r4 | ... | ...
Changed paths:
Pom.xml
So, what I think I need to do is:
If I find a start,
And I find another expression matching start before finding an expression
matching end,
Then throw away the first start; otherwise print.
I think this post might have my answer, but any attempt I have tried has
failed.

No comments:

Post a Comment