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
SED + Regex + SQL Input file primal Shell Programming and Scripting 10 04-14-2008 02:24 PM
read input file for batch job kinmak Shell Programming and Scripting 14 07-11-2007 08:22 AM
ls while read loop - internal read picking up wrong input dkieran Shell Programming and Scripting 2 05-14-2007 04:02 PM
read/writte/input data in file. dorek Shell Programming and Scripting 0 06-22-2006 08:31 AM
input inside while read loop jhansrod Shell Programming and Scripting 3 08-13-2005 11:46 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 09-23-2007
bonekrusher bonekrusher is offline
Registered User
  
 

Join Date: Sep 2007
Posts: 7
Apply Regex to input read

Hi I am very new to Unix Shell. I have a question:

How do you check the input value against a reqex?

For example using korn Shell:


Code:
echo "Please enter revision month: \c"
read revmon

if $revmon | egrep -c = '[A-Z]{3}[0-9]{2}"'

then
echo "OK"
else

echo "PLease re-enter a valid revision month (e.g. SEP07)"

fi

  #2 (permalink)  
Old 09-23-2007
radoulov's Avatar
radoulov radoulov is offline Forum Staff  
addict
  
 

Join Date: Jan 2007
Location: Варна, България / Milano, Italia
Posts: 2,926
With the Korn Shell you can use this:


Code:
print -n "Please enter revision month: "
read; case $REPLY in
([A-Z][A-Z][A-Z][0-9][0-9])print OK;;
(*)print KO;;
esac

P.S. In ths case it's globbing, not RE's.

Last edited by radoulov; 09-23-2007 at 12:51 PM.. Reason: addition
  #3 (permalink)  
Old 09-23-2007
bonekrusher bonekrusher is offline
Registered User
  
 

Join Date: Sep 2007
Posts: 7
Thanks... it worked perfect.

BTW what does esac mean?
  #4 (permalink)  
Old 09-23-2007
radoulov's Avatar
radoulov radoulov is offline Forum Staff  
addict
  
 

Join Date: Jan 2007
Location: Варна, България / Milano, Italia
Posts: 2,926
The letters of the word case reversed
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 02:38 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0