1837981 Members
1873 Online
110124 Solutions
New Discussion

counting with awk

 
SOLVED
Go to solution
lawrenzo_1
Super Advisor

counting with awk

Hi,

I am attempting to use awk to count the number of times a string appears:

awk '/Virtual SCSI Disk Drive/ {line=line+1};END{print line}'

I want to then say if line is greater than zero then print "virtual server"

where will the "if" statement be placed?

Thanks all.

Chris.

hello
3 REPLIES 3
Wouter Jagers
Honored Contributor
Solution

Re: counting with awk

Hi,

awk '/Virtual SCSI Disk Drive/ {line=line+1};END{print line; if(line>1){print "virtual server"} }'

.. or without printing the count:

awk '/Virtual SCSI Disk Drive/ {line=line+1};END{if(line>1){print "virtual server"} }'

..should work.

Cheers,
Wout
an engineer's aim in a discussion is not to persuade, but to clarify.
lawrenzo_1
Super Advisor

Re: counting with awk

thats works well!

great thanks very much.
hello
lawrenzo_1
Super Advisor

Re: counting with awk

ta
hello