Operating System - Linux
1753491 Members
4598 Online
108794 Solutions
New Discussion юеВ

Re: awk and else statements

 
SOLVED
Go to solution
Dennis Handly
Acclaimed Contributor

Re: awk and else statements

>Sandman: What should be the output of "" if "serv is a virtual server" should it output any lines that have "Virtual I/O Bus" or not?

I assumed that it outputs more than one. And with that assumption, my awk fragment worked.
Sandman!
Honored Contributor

Re: awk and else statements

So does my awk script Dennis but I wanted to clarify whether the author of the thread had made a typo in... if(line>1) ...where the intention was... if(line>0).

~cheers
lawrenzo_1
Super Advisor

Re: awk and else statements

ok thanks all,

looks like I forgot {} for the else statement.

will add this to my never ending notes.

Chris
hello
lawrenzo_1
Super Advisor

Re: awk and else statements

Thanks again all,

sandman you are correct line should be >0 and not >1.

all examples will help in the future.

Cheers

Chris.
hello
Dennis Handly
Acclaimed Contributor

Re: awk and else statements

>line should be >0 and not >1.

If this is the case, there is no need to count them up. Just do:
/Virtual I\/O Bus/ { print serv ": virtual server"; exit}
END { print serv ": not a virtual server"}

You can also make it simpler by just using grep:
| grep -q "Virtual I/O Bus"
if [ $? -eq 0 ]; then
echo "$i: virtual server"
else
echo "$i: not a virtual server"
fi
lawrenzo_1
Super Advisor

Re: awk and else statements

Thanks Dennis,

I am pretty handy with shell scripting so I am attempting to learn awk / sed and later on perl ....

but thanks for the examples.

Chris
hello