The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Help with grep and regex raichlea UNIX for Dummies Questions & Answers 14 04-16-2008 08:25 AM
regex question xiamin Shell Programming and Scripting 2 07-16-2007 04:40 AM
Regex deepakpv Shell Programming and Scripting 6 03-28-2007 01:18 AM
Regex?? Please help lunac UNIX for Dummies Questions & Answers 7 01-30-2007 10:13 AM
sed regex Shakey21 UNIX for Dummies Questions & Answers 4 01-31-2002 06:16 PM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1  
Old 08-08-2007
Registered User
 

Join Date: Aug 2007
Posts: 7
regex in variable

Hello!
I have problems with syntax...
I want a variable, that contains regex... is it possible?
Like $ a='.+->.+' and then use it in index ($0, "a").
I guess it won't work...

thank you
Reply With Quote
Forum Sponsor
  #2  
Old 08-08-2007
zazzybob's Avatar
Registered Geek
 

Join Date: Dec 2003
Location: Melbourne, Australia
Posts: 2,100
Yes - use eval. For example, here I define a regex then use it with egrep
Code:
$ regex='.+->.+'
$ echo -e "somestring->someotherstring\ndont_match_this"
somestring->someotherstring
dont_match_this
$ echo -e "somestring->someotherstring\ndont_match_this" | eval egrep "\$regex"
somestring->someotherstring
Cheers
ZB
Reply With Quote
  #3  
Old 08-08-2007
Registered User
 

Join Date: Aug 2007
Posts: 7
Thank you!
I know, that must be simple, but I can't figure out , why it is not working...
I need a regex, that finds strings like "Aaaa->Bbbbb" but not "Aaaa-> Bbbbb"

I tried .+-+>+.+ but it finds also with spaces...
and .+-+>+[A-Z]+ finds totally wrong...
Reply With Quote
  #4  
Old 08-08-2007
vgersh99's Avatar
Moderator
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 3,003
Code:
$ echo 'Aaaa->Bbbbb' | egrep '.+-+>+[^ ]+'
Aaaa->Bbbbb
$ echo 'Aaaa-> Bbbbb' | egrep '.+-+>+[^ ]+'
$
Reply With Quote
  #5  
Old 08-08-2007
Registered User
 

Join Date: Aug 2007
Posts: 7
Thanks Now I got it
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 02:17 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0