searching specefic word in shell script -
i have problem.please give me solution.
i have run command given below, list files contain string given "abcde1234".
find /path/to/dir/ * | xargs grep abcde1234
but here display files contain string "abcde1234567" also.but nee files contain word "abcde1234". modification shall need in command ??
when need that, use \<
, \>
mean word boundary. this:
grep '\<abcde1234\>'
the symbols \< , \> respectively match empty string @ beginning , end of word.
but that's me. correct way might use -w
switch instead (which tend forget about):
-w, --word-regexp select lines containing matches form whole words. test matching substring must either @ beginning of line, or preceded non-word constituent character. similarly, must either @ end of line or followed non-word constituent character. word-constituent characters letters, digits, , underscore.
one more thing: instead of find
+ xargs
can use find
-exec
. or grep -r
:
grep -w -r abcde1234 /path/to/dir/
Comments
Post a Comment