The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Regular Expressions ramky79 UNIX for Advanced & Expert Users 3 05-21-2008 02:13 PM
regular expressions melanie_pfefer UNIX for Dummies Questions & Answers 8 04-10-2008 01:24 AM
Develop and Test Regular Expressions with a Unit Testing Package iBot Oracle Updates (RSS) 0 04-06-2008 02:10 AM
regular expressions whatever Shell Programming and Scripting 4 05-20-2007 01:30 PM
regular expressions ragha81 UNIX for Dummies Questions & Answers 2 03-05-2007 04:24 PM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1  
Old 06-04-2008
Registered User
 

Join Date: Jun 2008
Posts: 2
Thumbs up how to test the regular expressions

Hi,

lam taking the IP address as input from the user. I want to test whether the user has entered the IP address in the right format or not.

Can any one suggest me the syntax to test the user given IP address ASAP. Its a bit urgent.


Regards,
Reply With Quote
Forum Sponsor
  #2  
Old 06-05-2008
Registered User
 

Join Date: Nov 2006
Posts: 54
this could help you:
How to validate an IP address
Reply With Quote
  #3  
Old 06-05-2008
era era is offline
Herder of Useless Cats
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,650
Code:
o1='1[0-9]{0,2}|2([6-9]|[0-4][0-9]?|5[0-4]?)?|[3-9][0-9]?'
o0='0|255|'"$o1"
if echo "$ip" | egrep -v "^($o1)(\.($o0)){2}\.($o1)$" >/dev/null; then
  echo invalid ip
fi
Reply With Quote
Google The UNIX and Linux Forums
Reply

Tags
regex, regular expressions

Thread Tools
Display Modes




All times are GMT -7. The time now is 05:48 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