0

I've been using this command:

find /path~ -type f | xargs grep -iR STRING1

to find strings in multiple files, but i was wondering me how can i find a string in multiple files, Case Sensitive, and even if the string is in other string.

For example:

I'm searching for: Encoder

  • if a file contains: abcdEncoder — should appear
  • if a file contains: abcdencoder — shouldn't appear
  • if a file contains: encoderEncoder — should appear

Maybe the question is a duplicate, but i haven't find it!

Cyrus
  • 84,225
  • 14
  • 89
  • 153
  • Please note that `find` without `-print0` combined with `xargs` often ends in frustration at a later point. – Ole Tange Aug 11 '14 at 23:00

1 Answers1

2

Remove the -i switch to make the matches case-sensitive. Your command already searches multiple files and doesn't care whether the string is inside another string, so that'll give you what you want.

Also note that using both find -type f and -R is redundant: as -type f ensures find will only print normal files for grep to examine, the -R (recurse through directories) option won't change anything. Alternatively, you can use -R to get rid of find and xargs: grep -R STRING1 /path~

jwodder
  • 54,758
  • 12
  • 108
  • 124