I want to refactor many JavaScript files in many directories which contain access to an object in this format: myObj.something.somethingElse and I want it to be myObj.getSomething(somethingElse) how can I achieve this in shell?
Asked
Active
Viewed 77 times
-1
-
2Please **[edit]** the question adding real and testable examples, also add what have you tried so far. – schrodingerscatcuriosity Nov 01 '21 at 16:50
-
1This is a rather basic use case for `sed` and a concept known as a *backreference*. In the abstract, your question is similar to the one answered [here](https://unix.stackexchange.com/a/120046/233270). You may find other helpful duplicates by filtering on the `[sed]` tag and searching for `backreference`. – Jim L. Nov 01 '21 at 17:10
-
Does this answer your question? [How can I replace text after a specific word using sed?](https://unix.stackexchange.com/questions/66878/how-can-i-replace-text-after-a-specific-word-using-sed) – Greenonline Nov 01 '21 at 17:34
-
The first object has `.something` and the second has `.getSomething`... is that correct or should the second also be `.something`? Or it is that, that you wish to replace, i.e. `s/.something/.getSomething/` Please clarify and give accurate examples. – Greenonline Nov 01 '21 at 17:36
1 Answers
0
You could probably give Sed (the stream editor) a try using it's replacement command s/regexp/replacement/.
felix
- 13
- 2