Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to
LinuxQuestions.org , a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free.
Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please
contact us . If you need to reset your password,
click here .
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
08-15-2011, 04:42 PM
#16
LQ Newbie
Registered: Mar 2011
Location: Miami
Distribution: Suse, RedHat, Ubuntu, CentOS
Posts: 29
Original Poster
Rep:
Quote:
Originally Posted by
MTK358
Code:
grep state:unreachable | wc -l
I've been trying and getting frustrated :-( How do I add another instance of grep. For example, how do I add another one in the same line.
I have this grep -c 'state:unreachable', but I need to add 'state:invalid'. To get a count of the "invalids"
08-15-2011, 06:13 PM
#17
LQ 5k Club
Registered: Sep 2009
Distribution: Arch x86_64
Posts: 6,443
The problem is that I don't know where you want the output. Anyway, maybe something like this:
Code:
awk 'BEGIN {
unreachable_count = 0
invalid_count = 0
}
/state:unreachable/ {
unreachable_count++
}
/state:invalid/ {
invalid_count++
}
END {
print "Invalid Count: " invalid_count
print "Unreachable Count: " unreachable_count
}'
08-15-2011, 07:16 PM
#18
LQ Newbie
Registered: Mar 2011
Location: Miami
Distribution: Suse, RedHat, Ubuntu, CentOS
Posts: 29
Original Poster
Rep:
Quote:
Originally Posted by
MTK358
The problem is that I don't know where you want the output. Anyway, maybe something like this:
Code:
awk 'BEGIN {
unreachable_count = 0
invalid_count = 0
}
/state:unreachable/ {
unreachable_count++
}
/state:invalid/ {
invalid_count++
}
END {
print "Invalid Count: " invalid_count
print "Unreachable Count: " unreachable_count
}'
The output can display on the screen. I just need a count to appear.
08-16-2011, 09:09 AM
#19
LQ Newbie
Registered: Mar 2011
Location: Miami
Distribution: Suse, RedHat, Ubuntu, CentOS
Posts: 29
Original Poster
Rep:
Quote:
Originally Posted by
MTK358
The problem is that I don't know where you want the output. Anyway, maybe something like this:
Code:
awk 'BEGIN {
unreachable_count = 0
invalid_count = 0
}
/state:unreachable/ {
unreachable_count++
}
/state:invalid/ {
invalid_count++
}
END {
print "Invalid Count: " invalid_count
print "Unreachable Count: " unreachable_count
}'
I tried that, it worked fine in its form. I've been trying to code it in such a way to have both counts = a single numeric output. Meaning "invalid" + "unreachable" = 5 (as an example)
08-16-2011, 11:18 AM
#20
LQ 5k Club
Registered: Sep 2009
Distribution: Arch x86_64
Posts: 6,443
How about this:
Code:
print invalid_count + unreachable_count
?
08-16-2011, 01:00 PM
#21
LQ Newbie
Registered: Mar 2011
Location: Miami
Distribution: Suse, RedHat, Ubuntu, CentOS
Posts: 29
Original Poster
Rep:
Quote:
Originally Posted by
MTK358
How about this:
Code:
print invalid_count + unreachable_count
?
Thanks!!
Thread Tools
Search this Thread
Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
All times are GMT -5. The time now is 05:01 AM .
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know .
Latest Threads
LQ News