![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| EOF checking the below | ramkrix | High Level Programming | 10 | 03-10-2008 10:43 PM |
| checking for non-zero value | philplasma | UNIX for Dummies Questions & Answers | 6 | 01-08-2008 01:51 PM |
| checking uid | filthymonk | Shell Programming and Scripting | 7 | 07-19-2007 07:40 PM |
| Checking for PXE | maestro@altiris | SUN Solaris | 5 | 05-24-2004 09:06 PM |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Checking variables
Firstly - aplogies to Vino
I need to check wether or not a variable called DATE is actually a date by doing the following - checking it is all numeric and secondly checking if it is 8 digits long. Any help appreciated |
| Forum Sponsor | ||
|
|
|
#2
|
|||
|
|||
|
clarification
Just to clarify my previous post - is there any function within UNIX that would allow me to check if something is 8 digits long etc. apart from grep
|
|
#3
|
||||
|
||||
|
Quote:
No ill-feelings from my side. And I hope none from yours too. Just letting you know on the rules that are followed in the forum. Quote:
Code:
echo $DATE | sed -n -e '/^[0-9]\{8\}$/p'
Vino |
|
#4
|
|||
|
|||
|
#!/bin/sh
date1=01234567 echo $date1 echo $DATE | sed -n -e '/^[0-9]\{8\}$/p' >> this produces the following 01234567 ./check.sh: /: cannot execute ./check.sh: [0-9]{8}$/p: not found sed: option requires an argument -- e any ideas? |
|
#5
|
||||
|
||||
|
You should echo $date1 to the sed command. Like this
Code:
#!/bin/sh
date1=01234567
echo $date1
echo $date1 | sed -n -e '/^[0-9]\{8\}$/p'
|
|
#6
|
|||
|
|||
|
This works great - thanks
What I need to do is to be able to echo 'DATE incorrect' if it is not 8 digits long or 'DATE correct' if it is..any ideas how to do this.. many thanks |
|
#7
|
||||
|
||||
|
I am lost on how to use sed along with &&. Probably somneone could help me out.
So a grep solution. Code:
echo $DATE | grep -q '/^[0-9]\{8\}$/' && echo "DATE correct" || echo "DATE incorrect"
Last edited by vino; 06-28-2005 at 05:15 AM. |
||||
| Google The UNIX and Linux Forums |