I’m trying to strip all the lines in an XML file that lie between the tags < KEYS > and < /KEYS >.
As a first pass at the problem I’ve gotten a regex that will match the first block of keys in the file but it doesn’t continue matching the other blocks in the file. I’ve tried adding “/g” to the regex and I’ve tried “-0777” to slurp the whole file at once and neither trick makes any difference. Below is the perl one liner:
perl -00 -ne 'print $1 if /(\s+\<KEYS\>\n\s+.*?\n\s+\<\/KEYS\>)/s' someFile.xml
and I get this output:
<KEYS> <KEY name="cone_id" type="long" nativeType="number(17)"/> <KEY name="bar_id" type="long" nativeType="number(32)"/> <KEY name="foo_type" type="int" nativeType="number(3)"/> </KEYS>
As stated above there are a lot more blocks in the file (which is nearly five thousand lines long) but the perl code isn’t messing with any of the rest.
Any suggestions?
Your one-liner will do what you want by making two changes:
iftowhile.goption to your regex:/.../gsAlternatively, it looks like the start and end tags of interest are on different lines, by themselves. If so, the flip-flop operator could be handy: