matching a regex using egrep not working


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting matching a regex using egrep not working
# 1  
Old 11-28-2011
matching a regex using egrep not working

Hi,

I'm trying to validate if a string matches a regular expression, but it is not working. Am I missing something? Do I need to scape any of the characters?

Code:
 if echo 'en-GB' | egrep '([a-zA-Z]{1,8})(-[a-zA-Z0-9]{1,8})*' >/dev/null; then
  echo Valid value
 fi


Thanks in advance
# 2  
Old 11-28-2011
Your regexp works with GNU grep, but you might need to escape the interval expressions (\{1,8\}) in some versions.
# 3  
Old 11-28-2011
Thanks CarloM.

I tried this:

Code:
if echo 'en-GB' | egrep '([a-zA-Z]\{1,8\})(-[a-zA-Z0-9]\{1,8\})*' >/dev/null; then
echo Valid value
fi

but still didn't work. Is anything else that might be wrong?

Last edited by skrtxao; 11-28-2011 at 11:56 AM..
# 4  
Old 11-28-2011
Your first post works for me...
Code:
root@bt:~#  if echo 'en-GB' | egrep '([a-zA-Z]{1,8})(-[a-zA-Z0-9]{1,8})*' >/dev/null; then
>   echo Valid value
>  fi
Valid value

which is your OS?

--ahamed
# 5  
Old 11-28-2011
Hi ahamed,

I believe is SunOS 5.10...
# 6  
Old 11-28-2011
Use /usr/xpg4/bin/egrep - Solaris egrep doesn't support interval expressions at all.
This User Gave Thanks to CarloM For This Post:
# 7  
Old 11-28-2011
That seems to work!

Thanks for the help.

skrtxao.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Egrep command is not working for me

my file is below REREGISTER is something to Failed to create the request Failed to create the request in not easy I know how REREGISTERcommand i run is egrep 'REREGISTER|Failed|to|create|the|request' test1 expected output REREGISTER is something to Failed to create the request i should... (2 Replies)
Discussion started by: mirwasim
2 Replies

2. UNIX for Dummies Questions & Answers

Regex matching with grep -l

I am trying to find patterns in files using grep -l -e. I specifically am searching for abc. I want any file that has abc in it, but not just the letters abc. I am searching for a pattern a followed by b followed by c. I have tried egrep -l and also I have tried the following: grep -el... (2 Replies)
Discussion started by: newbie2010
2 Replies

3. Shell Programming and Scripting

Egrep not working with -f option

Hi, I am trying to find out patterns in file 1 using patterns stored in file 2. Following is the code FILE1=inputfilename FILE2=blacklist blacklist 1203 97715555 20afEOF egrep -f $FILE2 $FILE1 but the above code is not working either using egrep or grep. Just for your... (10 Replies)
Discussion started by: siramitsharma
10 Replies

4. Shell Programming and Scripting

Regex for HP egrep

I seem to be having an issue with an egrep command and I think its the way it is interpreting my regex. I have a test file.. ###FIND THESE### telnet /telnet `telnet -l` ###Dont FIND THESE### donotfindtelnet telnetdontfind Working Regex on Linux/Solaris egrep '\<(telnet|rcp)\>' $file ... (4 Replies)
Discussion started by: nitrobass24
4 Replies

5. Shell Programming and Scripting

regex question using egrep

Hi, i have a a bunch of directories that are always named with six lowercase alpha's and either one or two numeric's (but no more) so for example names could be qwerty1 qwerty9 qwerty10 qwerty67 I am currently using two pattern matches to capture these names echo $DIR |... (8 Replies)
Discussion started by: rethink
8 Replies

6. Shell Programming and Scripting

Regex/egrep matching numbers in brackets

Experts: I don't know that regular expressions will ever be easy for me, so if one of you guru's could help out, I'd appreciate it. I'm trying to match a line in our syslog, but I can't figure out how to match a number inside a bracket. This is what I'm trying to match. "Jul 16 00:01:34... (2 Replies)
Discussion started by: jdveencamp
2 Replies

7. Shell Programming and Scripting

egrep regex

Hi, I have a file with some words divided into syllables by the character "|" (pipe). For example zu|ri|ghe|se.I would like a regex that matches all the words that are not divided in syllables.All the word that have no "|" pipe character.I have thought at $echo "zu|ri|ghe|se" | grep '' ... (7 Replies)
Discussion started by: and77
7 Replies

8. Shell Programming and Scripting

Perl regex help - matching parentheses

Let's say I'm trying to match potentially multiple sets of parentheses. Is there a way in a regular expression to force a match of closing parentheses specifically in the number of the opening parentheses? For example, if the string is "((foo bar))", I want to be able to say "match any number of... (7 Replies)
Discussion started by: cvp
7 Replies

9. Shell Programming and Scripting

REGEX: Matching Null?

I'm using the URL Regex feature of Squid for allowing sites via a list of regex strings to match allowed domains. The regex was actually copied from our previous proxy solution and it seemed to "just work". But, we've recently discovered that some domains (likely due to virtual hosts or host... (2 Replies)
Discussion started by: deckard
2 Replies

10. UNIX for Dummies Questions & Answers

egrep -e not working...!

:cool: fedora core 2 version 2.6.8-1.521 gnu/linux the last version of redhat that I was working with linux 8.0 a special version that came with a book.. on this version and on spider tools linux 0.9 the second version I worked with.. when i envoked egrep -e from file1 to file2 I would get the... (4 Replies)
Discussion started by: moxxx68
4 Replies
Login or Register to Ask a Question