Shashwat Shekhar Shukla Shashwat Shekhar Shukla - 4 years ago 112
Bash Question

Count total number of pattern between two pattern (using sed if possible) in Linux

I have to count all '=' between two pattern i.e '{' and '}'
Sample:

{
100="1";
101="2";
102="3";
};
{
104="1,2,3";
};
{
105="1,2,3";
};


Expected Output:

3
1
1

Answer Source

A very cryptic perl answer:

perl -nE 's/\{(.*?)\}/ say ($1 =~ tr{=}{=}) /ge'

The tr function returns the number of characters transliterated.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download