Grep multiple strings in same file

Find multiple strings in the same file using grep. Pass the results of grep to xargs with grep.

Find files containing both the add() method and the create() method.

$ grep -r -l "def add(" . | xargs grep -l "def create("

Edit the resulting files by enclosing the grep command in $().

$ vim $(grep -r -l "def add(" . | xargs grep -l "def create(")
Did this help you? Please let me know with a comment. Thank you
Posted .

Comments (RSS)

Leave a comment