Jan 11, 2005 #1 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.
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.
Jan 11, 2005 1 #2 PHV MIS Nov 8, 2002 53,708 FR 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 Upvote 0 Downvote
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
Jan 11, 2005 Thread starter #3 kHz MIS Dec 6, 2004 1,359 US 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. Upvote 0 Downvote
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.
Jan 11, 2005 #4 PHV MIS Nov 8, 2002 53,708 FR 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 Upvote 0 Downvote
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
Jan 11, 2005 1 #5 mikevh Programmer Apr 23, 2001 1,033 US Code: /^Non system users list/ {flag = 1; next} /^CPU usage info/ {flag = 0} !flag {next} /^[a-zA-Z]/ {count++} END {print count} Upvote 0 Downvote
Code: /^Non system users list/ {flag = 1; next} /^CPU usage info/ {flag = 0} !flag {next} /^[a-zA-Z]/ {count++} END {print count}
Jan 11, 2005 #7 mikevh Programmer Apr 23, 2001 1,033 US PHV, you noted that your code is just "A starting point," but it prints 4 for the sample input posted, not 3. Upvote 0 Downvote
PHV, you noted that your code is just "A starting point," but it prints 4 for the sample input posted, not 3.
Jan 11, 2005 #8 PHV MIS Nov 8, 2002 53,708 FR 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 Upvote 0 Downvote
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
Jan 11, 2005 1 #9 futurelet Programmer Mar 3, 2004 539 US /Non system users list/,/CPU usage info/{c+=1==NF&&/[^-]/} END{print c} Upvote 0 Downvote