The back-tics will automatically execute the grep command.
So,
      $var=`grep -E -i -c "abc|xyz|pqr" test.txt`;
will execute the grep command just like from the shell command line.
The output from the grep command will be captured in $var.
You can check the value of $? for the return value from grep.

Example:
$var=`grep -E -i -c "abc|xyz|pqr" test.txt`;
die "ERROR: Problem executing grep, ($!), stopped" if ( $? != 0 );

Try this...
First execute
      grep -E -i -c "abc|xyz|pqr" test.txt
from you shell command prompt.
Then write a perl script to the following and compare results:
      #!/usr/bin/perl
      $var`grep -E -i -c "abc|xyz|pqr" test.txt`;
      die "ERROR: Problem executing grep, ($!), stopped" if ( $? != 0 );
      print $var;
      exit(0);

Dave.

-----Original Message-----
From: ba2984 [mailto:[EMAIL PROTECTED]]
Sent: Monday, February 18, 2002 2:52 PM
To: david.b.deline
Cc: perl-unix-users
Subject: RE: [Perl-unix-users] Please help on GREP command


Then how do I execute the command in $var ? I want to check the return
code
of that grep command. Please help me. I am new to PERL.

Thanx..
-Bheem

-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED]]
Sent: Monday, February 18, 2002 11:47 AM
To: AITHA, BHEEMSEN (SBCSI)
Cc: [EMAIL PROTECTED]
Subject: RE: [Perl-unix-users] Please help on GREP command


Is that the exact line...?
Try:
$var=`grep -E -i -c "abc|xyz|pqr" test.txt`;
Remember to put your shell commands in back-tics...

Dave.

-----Original Message-----
From: ba2984 [mailto:[EMAIL PROTECTED]]
Sent: Monday, February 18, 2002 1:23 PM
To: perl-unix-users
Subject: [Perl-unix-users] Please help on GREP command


Hi listers,

I am using the following command in my perl script. But when I execute
the
script I am getting the error 

"Unrecognized file test: -E at test.pl line 9."

grep -E -i -c "abc|xyz|pqr" test.txt ;

Can someone please tell me what I am doing wrong here ?

All I wanted to do is to search for any of the stings abc, xyz or pqr in
the
file test.txt.

Thanx..
-Bheem
_______________________________________________
Perl-Unix-Users mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs



_______________________________________________
Perl-Unix-Users mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to