![]() |
|
|
|
|
|||||||
| 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 !! |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Execute a shell script using regular expressions | supergirl3954 | UNIX for Dummies Questions & Answers | 1 | 02-28-2008 07:20 AM |
| regular expressions | ragha81 | UNIX for Dummies Questions & Answers | 2 | 03-05-2007 03:24 PM |
| Help with regular expressions | arushunter | Shell Programming and Scripting | 13 | 12-23-2006 08:31 PM |
| using regular expressions in c shell control structure | ballazrus | Shell Programming and Scripting | 3 | 02-19-2006 08:59 PM |
| Regular expressions in sed | mfreemantle | UNIX for Dummies Questions & Answers | 3 | 02-11-2002 05:34 AM |
|
|
Submit Tools | LinkBack | Thread Tools | Display Modes |
|
|||
|
Regular Expressions in shell scripts <yawn>
Quite possibly a simple problem who's answer is evading me:
I am trying to write a sh shell script, part of which is *logically* trying to do the following: if [ $1 = [A-Za-z] ]; then ... fi if [ $1 = [0-9.] ]; then ... else ... fi Where the 1st condition is looking for a hostname passed as $1, the second a dotted-quad ip address, and the 3rd a catch-all error condition. I cannot work out how to use regex with the test ([) command. Would $1 always evaluate to "TRUE"? And therefore I would use something like: if [ $1 -a regex ]; then ... fi or not? BTW: I know the regex I have given in the example are not water-tight for their application ([0-9.] doesn't necessarily guarantee a dotted-quad by any means), this is a tool which is only going to be used by myself, and therefore isn't too much of a problem If someone would like to supply the regex for a dotted quad I would be most greatful :-), but no sweat. Thanks in advance. |
| Forum Sponsor | ||
|
|
|
|||
|
stright from Mastering Regular Expresstions by Oreilly page 124
Code:
^([01]?\d\d?|2[0-4]\d|25[0-5])\.([01]?\d\d?|2[0-4]\d|25[0-5])\. ([01]?\d\d?|2[0-4]\d|25[0-5])\.([01]?\d\d?|2[0-4]\d|25[0-5])\.$ btw this book is a book i think everyone that is into unix, programing, scripting should read. the hostname check is on page 167 Last edited by Optimus_P; 09-04-2001 at 02:38 PM. |
|||
| Google UNIX.COM |