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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Count between lines 3

Status
Not open for further replies.

kHz

MIS
Dec 6, 2004
1,359
US
What would be the easiest way to get a count with the text containing:

Non system users list.
----------------------

sasuser
oracle
oracledba

CPU usage info.
---------------

Thanks.
 
Can you please post some input samples and expected result ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
With a file containing:

Non system users list.
----------------------

sasuser
oracle
oracledba

CPU usage info.
---------------

I would like a count that shows the number of users:
3

I could do it with ksh and a typeset or a ${var:2:4} syntax, but with awk it could be easier, but I am not all awk-knowing.

Thanks.
 
A starting point:
awk '
f && NF==1{++u}
/^Non system users list/{++f}
/^CPU usage info/{print u;exit}
' /path/to/input

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Code:
/^Non system users list/ {flag = 1; next}
/^CPU usage info/ {flag = 0}
!flag {next}
/^[a-zA-Z]/ {count++}
END {print count}
 
PHV, you noted that your code is just "A starting point," but it prints 4 for the sample input posted, not 3.

 
Good catch mikevh, my bad.
/^--/{next}
f && NF==1{++u}
/^Non system users list/{++f}
/^CPU usage info/{print u;exit}

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
/Non system users list/,/CPU usage info/{c+=1==NF&&/[^-]/}
END{print c}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top