Dear Stack Exchange Community,
I see other solutions for this but I'm struggling with the regex I need to adapt them to my situation.
I have software-generated files that have lib object member properties with names that I need to replace. I need to use sed to find whatever name of the property, and replace it with the base file name.
Starting with a .js file named bobby.js that contains:
// stage content:
(lib.Scenario2IntroFigure0 = function(mode,startPosition,loop) {
stuff
}
Ending with the same bobby.js file but it now has:
// stage content:
(lib.bobby = function(mode,startPosition,loop) {
stuff
}
NOTE: Scenario2IntroFigure0 is different for every file, unfortunately.
Pseudocode describing what I think I should do:
A. Isolate the old name by looking for whatever is between this pattern::
// stage content:
(lib.
B. And this ending pattern:
= function(mode,startPosition,loop) {
C. Get the file base name itself with:
FILENAME=$(basename $1 '.js')
D. Replace old name with file base name and overwrite the file like:
sed -i "s/Scenario2IntroFigure0/$DA_FILE/g" $1
BUT where "Scenario2IntroFigure0" is whatever sed found between those two patterns.