Reputation: 1090
I am trying to print strings that contain any number of '=' signs in it. For that i am using the following command in bash
cat myfile | grep '^.*=+.*$'
I am writing ^ and $ for start and end of string
.* for any numnber of any character.
=+ for one or more equal(=) character.
But it doesn't show any output when executed.
But if i do simply:
cat myfile | grep '='
I get the desired output Why is this so?
What am i missing here ?
Upvotes: 0
Views: 52
Reputation:
The regex you're using isn't a basic posix regex. For example it tries to match the +
literally.
You should try using
cat myfile | grep -E '^.*=+.*$'
the -E
is for extended regular expressions.
Wikipedia has a nice comparison of posix basic and extended regular expressions where you also can see that +
is only a meta character in the extended version: https://en.wikipedia.org/wiki/Regular_expression#POSIX_extended
Upvotes: 1