I need little help from the community:
I have these two lines in a large text file:
Connected clients: 42
4 ACTIVE CLIENTS IN LAST 20 SECONDS
How I can find, extract and assign the numbers to variables?
clients=42
active=4
SED, AWK, GREP? Which one should I use?
clients=$(grep -Po '^(?<=Connected clients: )([0-9]+)$' filename)
active=$(grep -Po '^([0-9]+)(?= ACTIVE CLIENTS IN LAST [0-9]+ SECONDS$)' filename)
or
clients=$(sed -n 's/^Connected clients: \([0-9]\+\)$/\1/p' filename)
active=$(sed -n 's/^\([0-9]\+\) ACTIVE CLIENTS IN LAST [0-9]\+ SECONDS$/\1/p' filename)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With