using 'Not' while greping using regex

K

Kimi

Hi,

I would like to know how to use 'Not' option while grepping using regex

I have a file "File1.txt" whose contents are as below

----
INFO: error did not occur
ERROR: an error has occured
INFO: the machine has been started
---

cat File1.txt | grep '\error' ----> returns both the lines which has
error

I would like to retrieve only the lines which has "error" but not
"Info"

I appreciate your help. Thanks in advance

Regards,
Fahad
 
T

Tad McClellan

Kimi said:
I would like to know how to use 'Not' option while grepping using regex
cat File1.txt | grep '\error' ----> returns both the lines which has
error


This is the Perl newsgroup.

Did you mean to ask something regarding Perl?
 
A

anno4000

Kimi said:
Hi,

I would like to know how to use 'Not' option while grepping using regex

Your question is (apparently) about the Unix utility "grep". It
has nothing to do with Perl.
I have a file "File1.txt" whose contents are as below

Why do you cat File.text before you give it to grep? What is the
backslash before "error" for? Why quote "error"? Your command is
better written as

grep error File1.txt
I would like to retrieve only the lines which has "error" but not
"Info"

Your file doesn't contain the string "Info".

grep error File1.txt | grep -v INFO

Anno
 
K

Kimi

Hi,

Thanks for the help...

I am firing unix command from my Perl script.... sorry that i have
posted in here.

regards,
Kimi
 
J

Jürgen Exner

Kimi said:
I would like to know how to use 'Not' option while grepping using
regex

You just do. The first argument to grep() can be a general expression, it is
not limited to a regex only.
grep (not /...../, .....)
cat File1.txt | grep '\error' ----> returns both the lines which has
error

This does not look like Perl code?

jue
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top