Shell command for strings with decimal in brackets and uppercase and lowercase letters

I need to write a shell command with one line, which will count all lines starting with a decimal number in brackets, with a combination of upper and lower case letters and ending with a period.

I am very confused. I tried some, but I can not get the parentheses and ending with part of the period.

-1
source share
2 answers

The parenthesis syntax depends on the regex dialect used.

grep -c '^([0-9]*) [A-Za-z]*\.$' file

uses alphabetic parentheses, and

grep -Ec '^\([0-9]+\) [A-Za-z]+\.$' file

need backslashes. Also note the use of single quotes to prevent shell interference in arguments.

+1

:

cat file
Here are my data
Some number (12.3)
Even more
And more
And end here.
This does not count

awk '/\([0-9)+\.[0-9]+\)/ {f=1} f {a++} /[^0-9]\.[^0-9]*/ {f=0} END {print a}' file
4

, (<digit>.<digit>)
. [^0-9]\.[^0-9]*

0

All Articles