The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
need top 3 numbers shary Shell Programming and Scripting 4 03-25-2008 01:58 AM
ksh and hex numbers JamesByars Shell Programming and Scripting 2 01-15-2008 03:36 PM
grep or awk problem, unable to extract numbers baghera Shell Programming and Scripting 7 08-31-2007 05:42 PM
grep numbers range azmathshaikh Shell Programming and Scripting 1 08-08-2005 08:45 AM
Add some numbers! TalkShowHost Shell Programming and Scripting 3 05-15-2002 01:28 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 Rate Thread Display Modes
  #1 (permalink)  
Old 09-20-2005
shihabvk shihabvk is offline
Registered User
  
 

Join Date: May 2005
Posts: 54
grep for non numbers

Hi,
I want to find out whether a string contains non numbers and + and -
example :
Str="0005000A" - It contains A
Str="0005000+" - No problem

What I have done is ,
echo $Str | grep [a-z,A-Z]
I will have to list out all non numeric characters here..
Is there any easy way of doing it...


Shihab
  #2 (permalink)  
Old 09-20-2005
reborg's Avatar
reborg reborg is offline Forum Staff  
Administrator
  
 

Join Date: Mar 2005
Location: Ireland
Posts: 4,245
echo $Str | grep '[^0-9+\-]'

Last edited by reborg; 09-20-2005 at 11:58 AM.. Reason: add + and -
  #3 (permalink)  
Old 09-20-2005
Ygor's Avatar
Ygor Ygor is offline Forum Staff  
Moderator
  
 

Join Date: Oct 2003
Location: -31.96,115.84
Posts: 1,409
Try...
Code:
Chk=$(echo $Str | tr -d '[0-9+\-]')
if [[ -n $Chk ]] 
then
     echo It contains $Chk
else
     echo No Problem
fi

  #4 (permalink)  
Old 09-20-2005
blowtorch's Avatar
blowtorch blowtorch is offline Forum Advisor  
Supporter
  
 

Join Date: Dec 2004
Location: Singapore
Posts: 2,350
I think that the OP wants to get all strings that contain non numeric chars. So you would be leaving only the [0-9] in the grep or the tr.
i.e.

Code:
echo $Str | tr -d '[0-9]'

or

Code:
echo $Str | grep '[^0-9]'

  #5 (permalink)  
Old 09-20-2005
reborg's Avatar
reborg reborg is offline Forum Staff  
Administrator
  
 

Join Date: Mar 2005
Location: Ireland
Posts: 4,245
No that's not what OP asked for, it's exactly what Ygor posted, or if you chec the exit value what I posted.

just number with + or - are ok, anthing esle is not.
  #6 (permalink)  
Old 09-20-2005
blowtorch's Avatar
blowtorch blowtorch is offline Forum Advisor  
Supporter
  
 

Join Date: Dec 2004
Location: Singapore
Posts: 2,350
Oops.. sorry reborg, missed the second example there...
  #7 (permalink)  
Old 09-20-2005
reborg's Avatar
reborg reborg is offline Forum Staff  
Administrator
  
 

Join Date: Mar 2005
Location: Ireland
Posts: 4,245
Quote:
Originally Posted by blowtorch
Oops.. sorry reborg, missed the second example there...
Sorry if my post seemed abrupt, it wasn't intended that way, I was really short on time and my response came out a bit clipped.
Closed Thread

Bookmarks

Tags
grep or

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 03:07 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