What a long title. Essentially, what I have is a collection of files that need to be searched recursively with a regex, and replaced.
What I have so far works without capture groups, however it does nothing when using them. I am currently using a command that I found on another question:
grep -rlP "/\* *(\d+) *\*/ (.*)" . | xargs sed -i "s/\/\* *(\d+) *\*\/ (.*)/$2 \/\/ JD $1/g"
This regex is very confusing because it contains a lot of escaped asterisks and slashes, but essentially it takes in the string (for example)
/* 73 */ private static int last = -1000;
and replacing it with
private static int last = -1000; // JD 73
However, as I said earlier, it simply does not work, and the files are unchanged.
It works fine with an alternate regex that does not utilize capture groups
grep -rl "/\* *\*/ " . | xargs sed -i "s/\/\* *\*\/ //g"
but as soon as I try to introduce capture groups, it just silently fails.
I can tell it's searching through the files, as I can hear the drive spin up for a moment like with the successful one, but in the end the files remain unchanged.
Could it be possible to modify the command such that it works, or must I do it in a completely different way? Also, ideally the solution wouldn't require a bash loop. Thanks.
(
and)
are literal in sed basic regular expressions - see Why does my regular expression work in X but not in Y? – steeldriver Apr 28 '20 at 22:33