Reputation: 647
I want to matches those line of words:
{'ID': 'X.id: 4243.4, Y.id 534534', 'text': 'text - text'}
{'ID': 'X.id: 4247.4, Y.id 534534', 'text': 'text - text'}
{'ID': 'X.id: 42233.4, Y.id 534534', 'text': 'text - text'}
and I use this regular expression
to match them:
{'ID': 'X.id: [0-9]+.[0-9], Y.id [0-9]+', 'text': 'text - text'}
I tested it on https://regexr.com/ and it works.
However I tried to used this with grep using this command:
cat raport.log | grep "{'ID': 'X.id: [0-9]+.[0-9], Y.id [0-9]+', 'text': 'text - text'}"
Where do I do the mistake?
Upvotes: 0
Views: 95
Reputation: 626758
You may either use the ERE POSIX pattern by adding the -E
option or change the +
quantified subpatterns to their equivalents with *
(e.g. [0-9]+
=> [0-9][0-9]*
) (or escape +
in GNU grep
).
s="{'ID': 'X.id: 4243.4, Y.id 534534', 'text': 'text - text'}"
echo "$s" | grep -E "{'ID': 'X\.id: [0-9]+\.[0-9], Y\.id [0-9]+', 'text': 'text - text'}"
echo "$s" | grep "{'ID': 'X\.id: [0-9][0-9]*\.[0-9], Y\.id [0-9][0-9]*', 'text': 'text - text'}"
See an online demo
Note that you need to escape the dots to match literal .
chars.
Upvotes: 1