Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

have awk grep 2 variables

Status
Not open for further replies.

grazinggoat

Programmer
Mar 12, 2008
41
0
0
US
I'm trying to parse the following

I want to get a total of UP/DOWN from doing a status:

apps_status
sys1 UP
sys2 UP
sys3 DOWN
sys4 UP

right now I am doing

app_status |awk 'NR>1 { r[$2]++ } END {for (i in r) print r, i}'

how do i grep on up and down to feed into NR ?
so that I have UP=4 DOWN =1 ?


 
Something like this ?
Code:
app_status | awk 'NR>1{r[$2]++}END{for(i in r) printf "%s=%d ",i,r[i];printf "\n"}'

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Even simpler:
Code:
app_status | awk 'NR>1{r[$2]++}END{printf "UP=%d DOWN=%d\n",r["UP"],r["DOWN"]}'

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
both work! That later is what I was trying to pull out. I wasn't defining UP / DOWN on my attempts.
thnx!
 
I actually thought i'd have to define each something like UP=0; DOWN=0; then pull them from the array but your way simplified this.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top