Reputation: 29
I need to find a pattern that starts with a $ is followed by two numbers, a single character that is not a number, and anything else.
I know how to find a pattern starting in a dollar sign and followed by two numbers but I can't figure out how to check for one character that is not a number.
I also need to count how many lines have this pattern.
I have this so far:
grep -Ec '\$[0-9][0-9].....
I don't know what to do. Can someone please help? Any help would be much appreciated.
Upvotes: 0
Views: 102
Reputation: 13
I would second @realspirituals answer, and if you need to count how many lines have this pattern, you can count how many lines grep
ouputs by piping to wc -l
. In order to both show the lines and count them in one fell swoop, pipe the output like so
grep "\$[0-9]{2}[^0-9].*" | tee >(wl -l)
where tee
will split the output between wl
and STDOUT
. {2}
will cause the prior [0-9]
to match twice.
Upvotes: 0
Reputation: 11355
You can possibly try this regex \$[0-9][0-9][^0-9].*
\$[0-9][0-9][^0-9].*
Upvotes: 1
Reputation: 53563
The caret character inverts a selection group, so if [0-9]
is "match any digit" then [^0-9]
is "match any non-digit".
Upvotes: 1