• There has been a recent cluster of spammers accessing BARFer accounts and posting spam. To safeguard your account, please consider changing your password. It would be even better to take the additional step of enabling 2 Factor Authentication (2FA) on your BARF account. Read more here.

grep meeee - need help

Engel-07

New member
Joined
Apr 26, 2002
Location
City Of Angel
Moto(s)
R6
Hello,

I don't have any reference here...but I'm trying to do a simple grep command...and it's not working :(. I would like to search for wordA or wordB or wordC in the $stdout. Searching for just one word is easy...but i would like multiple words.

I'm trying to write it as just a 1 line command.

#!/bin/sh
ck_err=`cat $stdout|grep 'wordA' | wc -l`
echo 'FTP Errors Detected: '$ck_err
if [ "$ck_err" -ne "0" ]; then
blah blah blah
fi

thanks...
 
Engel-07 said:

#!/bin/sh
ck_err=`cat $stdout|grep -E 'wordA|wordB|wordC' | wc -l`
echo 'FTP Errors Detected: '$ck_err
if [ "$ck_err" -ne "0" ]; then
blah blah blah
fi

thanks...

use the -E option to treat each pattern as a regular expression. This should work. Hope it helps.

Brad
 
I tried that before, but I would get the following error message.

grep: illegal option - - E
usage: grep -hblcnsviw pattern file . . .

Thanks though!
 
My first question is which grep are you using... Linux and GNU grep, or something like solaris.... there is different syntax for them.
 
Engel-07 said:
I tried that before, but I would get the following error message.

grep: illegal option - - E
usage: grep -hblcnsviw pattern file . . .

Thanks though!

Ooops, wasn't paying attention, on second look, I'm guessing Solaris. If it is solaris you should use egrep instead of grep. The syntax would be something like the following:

`...cat...| egrep "wordA
wordB
wordC" | wc -l`
 
Last edited:
Thanks Unixgal! I tried using the one below, but it was searching for the exact string "wordA wordB wordC". I wanted it to be either wordA or wordB or wordC. So, I decided to use the egrep command w/ the -e option. However, when I use it as

grep -ewordA -ewordB

it would give me a wc of 0 if wordA or wordB does not exist. I give up...so I"m going to use the -f option instead.

#!/bin/sh
ck_err=`cat $stdout|egrep -f/BARF/exec/member.lis|wc -l`
echo 'FTP Errors Detected: '$ck_err
if [ "$ck_err" -ne "0" ]; then
....

This works for me...but i have to create the member.lis file.

Thanks everyone for your idea and help though! Much appreciated!

unixgal said:


Ooops, wasn't paying attention, on second look, I'm guessing Solaris. If it is solaris you should use egrep instead of grep. The syntax would be something like the following:

`...cat...| egrep "wordA
wordB
wordC" | wc -l`
 
did you actually put each word on a separate line, like in the example??? It should work fine as long as they are on separate lines or they have the carriage return '^J' between them.

Anyway, glad to help. :D :nerd
 
Wow...you're good! Yep...I tested it again..and it works great! Thanks a bunch....i'm learning something new today.

unixgal said:
did you actually put each word on a separate line, like in the example??? It should work fine as long as they are on separate lines or they have the carriage return '^J' between them.

Anyway, glad to help. :D :nerd
 
:nerd Alert :nerd

Also, in looking at your script, I'd also note that you can completeley get rid of the "| wc -l" pipe by using the "-c" option to grep/egrep, which gives you the count from the single command. Its more efficient/cool this way but works fine in either case. :nerd
 
:confused :confused :confused "startx" Ahhhh..... GUI. :blush

"I like my women hot, my beer cold, and my user interfaces graphical!" :laughing :laughing
 
Ahhh...so true..so true. Thanks..

unixgal said:
:nerd Alert :nerd

Also, in looking at your script, I'd also note that you can completeley get rid of the "| wc -l" pipe by using the "-c" option to grep/egrep, which gives you the count from the single command. Its more efficient/cool this way but works fine in either case. :nerd
 
Wolf said:
:confused :confused :confused "startx" Ahhhh..... GUI. :blush

"I like my women hot, my beer cold, and my user interfaces graphical!" :laughing :laughing

ahh you WUSS, the only reason to run X is to get more and larger CL's!!!(That and mozilla...) :laughing
 
Back
Top