grep a specific word and sum it

Posted by Kimi on Stack Overflow See other posts from Stack Overflow or by Kimi
Published on 2010-06-01T14:07:21Z Indexed on 2010/06/01 17:33 UTC
Read the original article Hit count: 460

Filed under:
|
|
|

I want to grep an environment variable

env | grep ABC_IJK[1,2]

currenlty defined variables are like this

ABC_IJK1=123
ABC_IJK1_XYZ=sn123:345
ABC_IJK2=999
ABC_IJK2_XYZ=sn321:999

I only want to get only this

ABC_IJK1=123
ABC_IJK2=999

get number of connections sum them(not 123 + 999) and save in N1 (this one has 2 connection)

so N1=2

get number of connections sum them and save in N2 for other machine (if this have four)

so N2=4

If the value is not there or the variable is not present then N1=1 for below:

ABC_IJK1=
ABC_IJK2=123

Then need to compare it with a MAX_CONNECTION variable

Thanks

© Stack Overflow or respective owner

Related posts about unix

Related posts about scripting