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
get substr? syamkp Shell Programming and Scripting 6 03-30-2008 11:08 PM
awk substr colesga Shell Programming and Scripting 2 07-11-2007 04:43 AM
Substr deepakwins UNIX for Dummies Questions & Answers 9 02-13-2007 09:58 PM
Using substr Klashxx Shell Programming and Scripting 2 05-08-2006 04:58 AM
How to use awk substr ? sabercats Shell Programming and Scripting 1 02-10-2006 04:01 PM

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

Join Date: Sep 2006
Posts: 43
awk or substr

i have a variable 200612
the last two digits of this variable should be between 1 and 12, it should not be greater than 12 or less than 1 (for ex: 00 or 13,14,15 is not accepted)
how do i check for this conditions in a unix shell script.

thanks
Ram
Reply With Quote
Forum Sponsor
  #2  
Old 03-12-2007
Registered User
 

Join Date: Feb 2005
Location: Broomfield, CO
Posts: 401
Nevemind; misread question.

Carl
Reply With Quote
  #3  
Old 03-12-2007
reborg's Avatar
Administrator
 

Join Date: Mar 2005
Location: Ireland
Posts: 3,590
Code:
[[ ${var#????} -lt 13 ]] && [[ ${var#????} -gt 0 ]] 
....
Reply With Quote
  #4  
Old 03-13-2007
cfajohnson's Avatar
Registered User
 

Join Date: Mar 2007
Location: Toronto, Canada
Posts: 784
Quote:
Originally Posted by ramky79
i have a variable 200612
the last two digits of this variable should be between 1 and 12, it should not be greater than 12 or less than 1 (for ex: 00 or 13,14,15 is not accepted)
how do i check for this conditions in a unix shell script.
Code:
var=200612
last2=${var#"${var%??}"}
if [ ${last2#0} -lt 1 ] || [ ${last2#0} -gt 12 ] 
then
   printf "INVALID %s\n" "$var" >&2
fi
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




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