LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 11-06-2014, 11:10 PM   #1
jags1984
Member
 
Registered: Mar 2013
Posts: 83

Rep: Reputation: Disabled
Using grep in perl with regex.


Using a regex in grep in perl code doesnt work.

Same is working in command line.

Code:
my PATTERN="fnOpenLog\([0-9a-zA-Z \*&]+,[0-9a-zA-Z \*&]+,[0-9a-zA-Z \*&]+\)"  

@srch = `grep -E -s -H -n -e $PATTERN "/home/SourceMAC/SourceMAC/src/test.txt"`;

The output of $#srch is -1 and the array @srch is null.
 
Old 11-06-2014, 11:57 PM   #2
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,505

Rep: Reputation: 2890Reputation: 2890Reputation: 2890Reputation: 2890Reputation: 2890Reputation: 2890Reputation: 2890Reputation: 2890Reputation: 2890Reputation: 2890Reputation: 2890
What is the solution to this question seeing it is marked as SOLVED?
 
Old 11-07-2014, 12:14 AM   #3
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 9,345

Rep: Reputation: 2747Reputation: 2747Reputation: 2747Reputation: 2747Reputation: 2747Reputation: 2747Reputation: 2747Reputation: 2747Reputation: 2747Reputation: 2747Reputation: 2747
you should not use backtick and grep inside a perl script, because perl itself is capable to do the same thing.
 
Old 11-10-2014, 05:48 AM   #4
jags1984
Member
 
Registered: Mar 2013
Posts: 83

Original Poster
Rep: Reputation: Disabled
The Solution is :


Use single quote: It will not resolve the regex and assign to the variable as it is(like a constant)
Quote:
my PATTERN='fnOpenLog\([0-9a-zA-Z \*&]+,[0-9a-zA-Z \*&]+,[0-9a-zA-Z \*&]+\)'
Since we need to resolve it in grep use double quote for the Variable.

Quote:
@srch = `grep -E -s -H -n -e "$PATTERN" "/home/SourceMAC/SourceMAC/src/test.txt"`;
 
  


Reply


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
Confusing issue with Perl regEx - Regex check seems to require variable being set EnderX Programming 1 09-07-2013 04:36 AM
REGEX with grep Anna1987 Linux - Newbie 9 03-09-2013 07:56 AM
[SOLVED] differences between shell regex and php regex and perl regex and javascript and mysql golden_boy615 Linux - General 2 04-19-2011 01:10 AM
Perl to find regex and print following 5 lines after regex casperdaghost Linux - Newbie 3 08-29-2010 08:08 PM
perl grep not finding regex WindozBytes Programming 6 05-29-2008 01:21 PM


All times are GMT -5. The time now is 01:20 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration