1847146 Members
5954 Online
110263 Solutions
New Discussion

Re: About the script

 
SOLVED
Go to solution
peterchu
Super Advisor

About the script

grep -qiE '\*|ERROR' value(logfile)

I have above script , but I am not understand what is the function ? is it grep all the word "ERROR" under the root directory ? thx
4 REPLIES 4
Sanjay Kumar Suri
Honored Contributor
Solution

Re: About the script

man grep has following to offer:

-q (Quiet) Do not write anything to the standard output, regardless of matching lines. Exit with zero status upon finding the first matching line. Overrides any options that would produce output.

-E Extended regular expressions. Each pattern specified is a sequence of one or more EREs. The EREs can be separated by newline characters or given in separate -e expression options. A pattern matches an input line if any ERE in the sequence matches the contents of the input line without its trailing newline character. The same functionality is obtained by using egrep.

-i Ignore uppercase/lowercase distinctions
during comparisons.

On a sample logfile
$ cat logfile
error
askaskaserror
sdsdsd\error
\
sdsdsd|error

$grep -qiE '\*|ERROR' logfile
$echo $?
0

sks

A rigid mind is very sure, but often wrong. A flexible mind is generally unsure, but often right.
peterchu
Super Advisor

Re: About the script

thx reply,

what is the mean of \*|EROOR ? is it the same as grep -i "EROOR" \* ? thx
H.Merijn Brand (procura
Honored Contributor

Re: About the script

No, it is about the same as

grep -q -i -e '*' -e 'ERROR'

the '|' (pipe) means OR

Enjoy, Have FUN! H.Merijn
Enjoy, Have FUN! H.Merijn
Anupam Anshu_1
Valued Contributor

Re: About the script

Please refer to the manpage of regexp(5) for regular expressions and Extended regular expressions.

To me it looks like grep(1) would match either '*' character or 'error'(case ignored because of -i option of grep(1)).

I tried grep(1) with -E & -i option to verify the output,

---------------------------
$ grep -iE "\*|ERROR" tfile
abcd *
Error
$
----------------------------

So it holds good for what I stated above.

Regards,

Anshu