Domanda

If I have a file named test with 1 line of text: \<.abc

and do a grep '\<abc' test

why do I get a result?

How can I fix this?

È stato utile?

Soluzione

In general when working with regular expressions if you want to match a literal backslash character it needs to be escaped, so you should see the correct behavior if you use grep '\\<abc' test.

As for what the \< is actually doing in the regular expression, this is from the grep man page:

   The symbols \< and \>  respectively  match  the  empty  string  at  the
   beginning and end of a word.
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top