This is my grep search
grep 'Invoker_Slark*' true_pairscore.txt
But it returns the line Invoker_Slardar
. Even though the file contains Invoker_Slark
. Why is that?
grepregular expression
This is my grep search
grep 'Invoker_Slark*' true_pairscore.txt
But it returns the line Invoker_Slardar
. Even though the file contains Invoker_Slark
. Why is that?
Best Answer
The reason is that
Invoker_Slark*
is considered a regular expression wherek*
means: "zero or more occurrences of k"That's different from shell globbing patterns where
*
means 0 or more characters.To search for
Invoker_Slark
anywhere in the line, you need:grep 'Invoker_Slark' true_pairscore.txt
orgrep -x '.*Invoker_Slark.*' true_pairscore.txt
If the search string must be at the beginning of the line then this has to be changed to:
grep '^Invoker_Slark' true_pairscore.txt
orgrep -x 'Invoker_Slark.*' true_pairscore.txt