DEV Community

loading...

How to print every file (with the line number) containing a pattern?

webeleon profile image Julien Prugne ・1 min read

While editing a massive codebase, massive like a monorepo with 247 sub projects...

I need to find every file containing a certain pattern.
Webstorm is, once again, indexing... It will finish in 15 minutes....

Let's use a good'ole grep command.

grep --exclude-dir={node_modules,dist,build} -rnw $(pwd) -e 'my secret pattern'

It will print every absolute file path followed by the line number inside the file and the line containing the pattern.

Have fun!

Discussion (0)

pic
Editor guide