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 > 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
Korn: How to loop through a string character by character shew01 Shell Programming and Scripting 10 12-02-2008 07:58 AM
read a variable character by character, substitute characters with something else vipervenom25 UNIX for Dummies Questions & Answers 2 06-06-2008 03:18 PM
Search in variable for character rorey_breaker Shell Programming and Scripting 1 09-27-2007 07:05 AM
Perl code to differentiate numeric and non-numeric input Raynon Shell Programming and Scripting 11 08-04-2007 10:32 AM
Search for a non zero character in file misenkiser Shell Programming and Scripting 4 10-09-2006 02:01 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 12-14-2007
lumix lumix is offline
Registered User
  
 

Join Date: Dec 2007
Posts: 15
Bourne: search for a non-numeric character in $VAR

if $1 = "123x456", how can I test for the non-numeric character 'x' in that string. I've tried expr with "[^0-9]" but it did not find the x. Any ideas? Can this perhaps be done with sed?

Thanks.
  #2 (permalink)  
Old 12-14-2007
radoulov's Avatar
radoulov radoulov is offline Forum Staff  
addict
  
 

Join Date: Jan 2007
Location: Варна, България / Milano, Italia
Posts: 2,794
If only for unsigned integers:

bash3

Code:
bash 3.2.25(1)$ [[ 12345x6 =~ [^0-9] ]]&&printf "No digit found: %s\n" "$BASH_REMATCH"
No digit found: x
Otherwise:

Code:
v="12345x6"
case $v in (*[!0-9]*) printf "No digit found: %s\n" "$v";;esac
For old, old sh use this syntax:

Code:
case $v in *[!0-9]*) printf "No digit found: %s\n" "$v";;esac
P.S. Just noticed "Bourne" If not bourne again 3, then [23]

Last edited by radoulov; 12-14-2007 at 01:06 PM..
  #3 (permalink)  
Old 12-14-2007
lumix lumix is offline
Registered User
  
 

Join Date: Dec 2007
Posts: 15
I had a feeling it might require case. Thank you so much.
Sponsored Links
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 01:36 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language translation by Google.
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