LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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

Reply
 
Search this Thread
Old 08-15-2011, 05:42 PM   #16
Q_Linux
LQ Newbie
 
Registered: Mar 2011
Location: Miami
Distribution: Suse, RedHat, Ubuntu, CentOS
Posts: 29

Original Poster
Rep: Reputation: 0

Quote:
Originally Posted by MTK358 View Post
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"
 
Old 08-15-2011, 07:13 PM   #17
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443
Blog Entries: 3

Rep: Reputation: 714Reputation: 714Reputation: 714Reputation: 714Reputation: 714Reputation: 714Reputation: 714
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
     }'
 
Old 08-15-2011, 08:16 PM   #18
Q_Linux
LQ Newbie
 
Registered: Mar 2011
Location: Miami
Distribution: Suse, RedHat, Ubuntu, CentOS
Posts: 29

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by MTK358 View Post
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.
 
Old 08-16-2011, 10:09 AM   #19
Q_Linux
LQ Newbie
 
Registered: Mar 2011
Location: Miami
Distribution: Suse, RedHat, Ubuntu, CentOS
Posts: 29

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by MTK358 View Post
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)
 
Old 08-16-2011, 12:18 PM   #20
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443
Blog Entries: 3

Rep: Reputation: 714Reputation: 714Reputation: 714Reputation: 714Reputation: 714Reputation: 714Reputation: 714
How about this:

Code:
print invalid_count + unreachable_count
?
 
Old 08-16-2011, 02:00 PM   #21
Q_Linux
LQ Newbie
 
Registered: Mar 2011
Location: Miami
Distribution: Suse, RedHat, Ubuntu, CentOS
Posts: 29

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by MTK358 View Post
How about this:

Code:
print invalid_count + unreachable_count
?
Thanks!!
 
  


Reply

Tags
awk, script, sed, shell, websphere


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Simple shell script vinaytp Linux - Newbie 4 03-30-2011 04:32 AM
please help with simple shell script blancs Programming 6 11-02-2008 05:10 AM
need shell-script help (very simple) oskar Linux - General 6 03-12-2008 08:08 AM
Need help getting started simple simple shell script dhonnoll78 Programming 6 12-17-2007 06:34 PM
Simple C Shell script is not so simple elconde Programming 2 09-17-2001 12:53 AM


All times are GMT -5. The time now is 11:50 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration