Using grep -rin with the string value has underscores
If wp_get_attachment_url
is actually an URL that must be interpreted literally, use single quotes to prevent the shell from interpreting characters. Furthermore, use the -F
option of grep
to avoid it from interpreting the pattern as a regular expression.
http://example.com/?id=1
interpreted as a regular expression would match either http://example.comid=1
or http://example.com/id=1
, but not http://example.com/?id=1
.
The command becomes:
grep -rinF 'http://example.com/?id=1' *
If the pattern contains a '
, use '\''
to escape it:
grep -rinF 'mornin'\'' all' *
A hint: *
matches all non-hidden files in the current directory. If you want to match dot-files as well, just grep the current directory recursively (-r
):
grep -rinF 'search term' .
Related videos on Youtube
garbage collection
Author of Just Enough Ruby to Get By Follow me @jasoki
Updated on September 18, 2022Comments
-
garbage collection over 1 year
I am trying to run this command.
grep -rin "wp_get_attachment_url" *
But the underscores (_) in the string value seems to mess up the grep command. How do I search the string values that have underscores?
-
htorque over 12 yearsCan you explain "mess up the grep command"? It works fine here in Ubuntu 11.10.
-