Is there a way to grep
(or use another command) to find exact strings, using NO regex?
For example, if I want to search for (literally):
/some/file"that/has'lots\of"invalid"chars/and.triggers$(#2)[*~.old][3].html
I don't want to go through and escape every single "escapable". Essentially, I want to pass it through, like I would with echo
:
$ echo "/some/file\"that/has'lots\of\"invalid\"chars/and.triggers$(#2)[*~.old][3].html" /some/file"that/has'lots\of"invalid"chars/and.triggers$(#2)[*~.old][3].html
Grep to Match First and Last Character. You can also use the grep command to find an exact match by using the beginning(^) and ending($) character.
The easiest of the two commands is to use grep's -w option. This will find only lines that contain your target word as a complete word. Run the command "grep -w hub" against your target file and you will only see lines that contain the word "hub" as a complete word.
Exact Match with -w Option The -w option is used to match specified term exactly for the given content. Actually the -w option is created to match words where single word can match.
Either use grep -E (the modern form for egrep ) so | be treated as an extended regular expression alternation operator, but then you'd need to escape every other regular expression operator (like . , ? , * , ^ , $ , \ , [ , ( , ) , { , } ) in your fixed strings.
Use fgrep
, it's the same as grep -F
(matches a fixed string).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With