Karthick
Karthick

Reputation: 21

How to count exact match of certain patterns in a text file using linux shell command?

I want to find the count of certain pattern in a text file which contains lot of mixed patterns also using linux shell command.

I have a text file which contains below patterns,

[--------------]

[+--------------+]

[+----------+------------+--------------------+]

[+---------------------+---------------------+]

How to find exact count of only first pattern [--------------]?

Note: Don't include square bracket as a pattern. Only special character inside square bracket is a pattern.

Upvotes: 0

Views: 72

Answers (1)

wuba
wuba

Reputation: 11

cat ./file | sed -e 's/\]/\]\n/' |grep "\[--------------\]" -c

cat reads file
sed replace ] with ]\n
grep searches every line for your expression and prints the number of lines -c

Upvotes: 1

Related Questions