The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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
Grep or Sed jazz8146 UNIX for Dummies Questions & Answers 5 11-13-2007 05:43 AM
how to exclude the GREP command from GREP yamsin789 UNIX for Advanced & Expert Users 2 10-05-2007 02:59 AM
using Grep with a tab Adriel UNIX for Dummies Questions & Answers 2 05-03-2007 01:51 AM
Make grep -c display like grep -n? Jerrad Shell Programming and Scripting 2 08-25-2006 12:20 AM
grep help malaymaru SUN Solaris 3 05-10-2005 03:07 PM

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 Rating: Thread Rating: 1 votes, 3.00 average. Display Modes
  #1 (permalink)  
Old 06-17-2008
thana thana is offline
Registered User
  
 

Join Date: Jan 2008
Posts: 55
Help in grep

Hi folks,
I have a shell script which accepts 1 argument. Now I need the check if the argument that has been passed is of correct format.
The argument passed will be a date of the format ddmmyy. I want to match the pattern something like grep -e "[0-9]{6}".

Can any one please help me.
  #2 (permalink)  
Old 06-17-2008
spirtle spirtle is offline
Registered User
  
 

Join Date: Jun 2008
Location: Scotland
Posts: 150
How about using -c flag
Code:
echo $1|grep -Ec '^[0-9]{6}$'
which will give you 1 if the pattern (6 digits, no more and no less) matches and 0 otherwise?
  #3 (permalink)  
Old 06-17-2008
jim mcnamara jim mcnamara is online now Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,719
note - that does not tell you if it is a valid date,:
Code:
>echo 999999 |grep -Ec '^[0-9]{6}$'
>1
Do you need to validate that it is a correct date or just numeric?
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 11:56 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