-1

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?

4
  • 2
    Please edit the question adding real and testable examples, also add what have you tried so far.CommentedNov 1, 2021 at 16:50
  • 1
    This 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. You may find other helpful duplicates by filtering on the [sed] tag and searching for backreference.
    – Jim L.
    CommentedNov 1, 2021 at 17:10
  • Does this answer your question? How can I replace text after a specific word using sed?CommentedNov 1, 2021 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.CommentedNov 1, 2021 at 17:36

1 Answer 1

0

You could probably give Sed (the stream editor) a try using it's replacement command s/regexp/replacement/.

    You must log in to answer this question.

    Start asking to get answers

    Find the answer to your question by asking.

    Ask question

    Explore related questions

    See similar questions with these tags.