Sonique
Sonique

Reputation: 7110

grep and sed - find function calls in files

I need to find usages of class methods in project folder (for refactoring).

Now I'm search with grep -nr "className." .. And get list like:

file1.js:874:    var x = className.method1() + m;
file5.js:330:    console.log(className.method2());
etc...

My goal is to get only methods that used in files without any code around.

For example if we have line in file like:

if(className.varIsSetted())

In output get only:

varIsSetted

Also I want to remove duplicates and sort lines, but it's not problem with sort and uniq at the end of pipe.

Upvotes: 0

Views: 1042

Answers (1)

Avinash Raj
Avinash Raj

Reputation: 174786

You could try the below grep command.

grep -oPr '\bclassName\.\K\w+(?=\()'

\K discards the previously matched chars from printing at the final.

Upvotes: 1

Related Questions