Quantcast
Channel: UNIX and Linux Forums
Viewing all articles
Browse latest Browse all 16232

Count occurrence of string (based on type) in a column using awk

$
0
0
Hello,

I have a table that looks like what is shown below:

Code:

AA
BB
CC
XY
PQ
RS
AA
BB
CC
XY
RS

I would like the total counts depending on the set they belong to:

if search pattern is in
Code:

{AA, BB, CC} --> count them as Type1 | wc -l
or if pattern is in
Code:

{XY, RS, PQ} --> count them as Type2 | wc -l
So, w.r.t the above table the output should be Type1 = 6 & Type2 Counts = 5

I can do a simple awk for each type like so and then add them together, but it does not seem very efficient. Any (one liner)suggestions?

Many thanks!
~Guss

Viewing all articles
Browse latest Browse all 16232

Trending Articles