Greetings all,
I am trying to match a string, and after that insert a few lines above that match.
The string is "Version 1.0.0". I need to insert a few lines ONLY above the first match (there are many Version numbers in the file). The rest of the matches must be ignored. The lines I need to insert are (above Version 1.0.0):
Version 2.0.0
-------------
2012-01-11 - user_name
prod 2.0.0
This needs to be done in all files named VERSIONINFO recursively from the top level folder.
I have tried to do this in a perl file:
#-------------
@readme_files = `find . -name "VERSIONINO"`;
foreach $readmes (@readme_files) {
chomp ($readmes);
$ver_match = `sed -n '/^Version [0-9].[0-9].[0-9]/{p;q;}' "$readmes"`;
if ($ver_match)
{push (@vermatch, $ver_match);
`sed -i '/"$ver_match"/ i \Version 2.0.0\\n-------------\\n2012-01-15 - user_name\\nprod 2.0.0\\n' "$readmes"`;
}
else {
push (@no_vermatch, $readmes);
}
}
print "Versions found @vermatch\n";
print "Files with no version numbers @no_vermatch\n";
But the problem is with SED that does the actual insert. the error is:
sed: -e expression #1, char 15: unterminated address regex
sed, that picks out the first match works fine, the insert part does not. I tried escaping characters, but have not been successful. I believe I need to escape some characters in the sed insert command, but have been lost now.
Would appreciate any input to solve this.
Thanks in advance,