![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| 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 |
| Grep command | nickg | UNIX for Dummies Questions & Answers | 14 | 4 Days Ago 08:22 AM |
| how to exclude the GREP command from GREP | yamsin789 | UNIX for Advanced & Expert Users | 2 | 10-04-2007 11:59 PM |
| grep command help | ishmael^soyuz | Shell Programming and Scripting | 4 | 07-11-2007 06:01 AM |
| grep command | pmsuper | UNIX for Dummies Questions & Answers | 6 | 11-22-2006 03:12 AM |
| grep command | debasis.mishra | Shell Programming and Scripting | 1 | 03-27-2006 10:53 PM |
|
|
Submit Tools | LinkBack | Thread Tools | Display Modes |
|
|||
|
grep command
how can i grep number in a file
if i want to grep 1234 can i use? read inp1 inp2 echo inp1 > inp1.txt ;echo inp2 > inp2.txt if inp=`grep -w [0-9] inp1.txt` -o inp1=`grep -w [0-9] inp2.txt` thanks |
| Forum Sponsor | ||
|
|
|
|||
|
Numeric Check
As I know, there is no straight forward numeric check in shell script.
Through logic you can do. -- typeset -i num echo "Please enter string :" read str num=`expr $str + 1 2>/dev/null` if [ $? -eq 0 ] then echo "Entered string is a number $str" else echo "Entered string is not a number $str" fi -- Hope it will help Thanks Sumit |
|
|||
|
Be sure to add an extra check whether the user has given 0 as input when using sumitc's suggestion, which is the far better way to accomplish what you really want.
Generally one could render your idea in a more elegant way as follows Code:
read value value=`echo $value|grep -w [0-9]` |
|
|||
|
grep command
hi,
that does work but it doesnot support input more than one digit if i want to enter number with 2 digits, the command does not work, what should i alter to allow the code to read input of more than one digit? thanks |
|||
| Google The UNIX and Linux Forums |