Bourne: search for a non-numeric character in $VAR


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Bourne: search for a non-numeric character in $VAR
# 1  
Old 12-14-2007
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  
Old 12-14-2007
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" Smilie If not bourne again 3, then [23] Smilie

Last edited by radoulov; 12-14-2007 at 01:06 PM..
# 3  
Old 12-14-2007
I had a feeling it might require case. Thank you so much.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Search of multiple numeric entries in an output file

Hello Tech Guys, I have two files named check.txt and output.txt Content of check.txt 620070527336551 40201800027285 620070551928314 40201800027285 620070534376312 40201800027285 620070536668046 02711306140261 620070248491123 02711306140261 620070553851296 02711306140261... (4 Replies)
Discussion started by: Xtreme
4 Replies

2. Shell Programming and Scripting

Extract all first numeric character from a string

Hello, I have a file of strings a below:- 4358RYFHD9845 28/COC/UYF984 9834URD 98HJDU I need to extract all the first numeric character of every sting as follows:- 4358 28 9834 thanks to suggest ASAP Regards, Jasi Use code tags, thanks. (7 Replies)
Discussion started by: jassi10781
7 Replies

3. Red Hat

monitoring search strings /var/log/messages

Hello Everyone, I am setting up monitoring system for linux server, I need to add few some common error message in monitoring file which can search those strings in /var/log/messages file on the client. can someone suggest few error messages. Thanks, (2 Replies)
Discussion started by: bobby320
2 Replies

4. UNIX for Dummies Questions & Answers

SED command to search for numeric and replace

Hi I am very new to linux and scripting. I need to replace numbers abc with number xyz inputting from a reference file. I used the following command - sed "s/$grd/$lab/" , where $grd and $lab comes from reference file. The problem is the above line doesnt take care of space..... (1 Reply)
Discussion started by: ajayh
1 Replies

5. Shell Programming and Scripting

validating a input file for numeric and character

i have a input file like this 001|rahim|bajaj|20090102 while reading the file i need to check whether the first column is a number second column is a name is there any methodology to check for the same thanks in advance (2 Replies)
Discussion started by: trichyselva
2 Replies

6. Shell Programming and Scripting

check whether it is a non-numeric character

Below is the abstract of the script which is working fine. if ] then error_process "Invalid month format." return 1 fi I am doing validation for month and it errors if the value is > 12 or < 0. In addition, I want to add another condition to error if it... (2 Replies)
Discussion started by: sony_dada
2 Replies

7. UNIX for Dummies Questions & Answers

assigning (numeric) command output to var tcsh

Hello, I'm trying to assign a numeric value that is returned from one of my programs to a variable in tcsh. I want to do: @ r10 = './my_prog file 35' where ./my_prog file 35 returns a decimal value, but this doesn't work. How do I achieve the desired result? Janet (4 Replies)
Discussion started by: psran
4 Replies

8. Shell Programming and Scripting

:-) 1213: Character to numeric conversion error. Plz help

Dear friends, I am new to Unix/Linux. I am trying to run following query but getting an error msg... Please can u people help me in this? Query: echo "select status_ac from db_acct where acct_num=AAA000337" | dbaccess elstest Error: 217: Column (amd000337) not found in any table in the... (2 Replies)
Discussion started by: anushree.a
2 Replies

9. Shell Programming and Scripting

Perl code to differentiate numeric and non-numeric input

Hi All, Is there any code in Perl which can differentiate between numeric and non-numeric input? (11 Replies)
Discussion started by: Raynon
11 Replies

10. UNIX for Dummies Questions & Answers

how to check first character in var's value.

Currently my script works like this: DATE_dd=5 # Assume this is user input. (User can enter 1, 2, 3, .. 10, 11, 12) if ; then DATE_D=" ${DATE_dd}" file_name="${DATE_yyyy}${DATE_mm}0${DATE_dd}.csv" else DATE_D=${DATE_dd} ... (7 Replies)
Discussion started by: yongho
7 Replies
Login or Register to Ask a Question