check whether it is a non-numeric character


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting check whether it is a non-numeric character
# 1  
Old 01-06-2009
Bug check whether it is a non-numeric character

Below is the abstract of the script which is working fine.

if [[...
${l_file_mm} -gt 12 || ${l_file_mm} -eq 00 || \
]]
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 is not a number.
Say, if it is 'ab', I want to error. What's the simpler way ?
Thanks.
# 2  
Old 01-06-2009
What shell are you using? Some support globbing or regular expressions for things like this.
# 3  
Old 01-06-2009
Quote:
Originally Posted by sony_dada
Below is the abstract of the script which is working fine.

if [[...
${l_file_mm} -gt 12 || ${l_file_mm} -eq 00 || \
]]
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 is not a number.
Say, if it is 'ab', I want to error. What's the simpler way ?
Thanks.

This question was asked yesterday. You should search the forum before posting:
https://www.unix.com/shell-programmin...#post302273787
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. 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

2. Shell Programming and Scripting

Check whether input is numeric

Hello there, find below for my code first: $pdp_asaba=`cat /tmp/temp_total | grep asaba | sed 's/*//g'` if ]] then pdp_asaba=0 fi $pdp_abuja=`cat /tmp/temp_total | grep abuja | sed 's/*//g'` if ]] then pdp_abuja=0 fi $pdp_ojota=`cat /tmp/temp_total | grep ojota | sed 's/*//g'` if ... (3 Replies)
Discussion started by: infinitydon
3 Replies

3. Shell Programming and Scripting

check if a string is numeric

I checked all the previous threads related to this and tried this. My input is all numbers or decimals greater than zero everytime. I want to check the same in the korn shell script. Just validate the string to be numeric. This is what I am doing. var="12345" if ) -o "$var" !=... (14 Replies)
Discussion started by: megha2525
14 Replies

4. Shell Programming and Scripting

How to check for a Numeric Value?

Using shell, I have a variable, how can I check that variable for a numeric value such as "41.0"? My program needs to do one things if the numeric value is found, and another if something else such as a string of letter is found. is there a specific character that denotes a numeral? The... (2 Replies)
Discussion started by: chagan02
2 Replies

5. Programming

check the given string is numeric or not.

Hi, how to check the given string is numeric or not , without converting ( using strtol...). for ex: if string is C01 - non-numeric data if string is 001 - numeric data TIA (11 Replies)
Discussion started by: knowledge_gain
11 Replies

6. 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

7. 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

8. Shell Programming and Scripting

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 "" but it did not find the x. Any ideas? Can this perhaps be done with sed? Thanks. (2 Replies)
Discussion started by: lumix
2 Replies

9. Shell Programming and Scripting

to check variable if its non numeric

if test $b -ne then echo "\n\n\n\tPassword reset has been done successfully" else echo "\n\n\n\tAn error occurred" fi i want to check whether $b is non-numeric so how to do that? (3 Replies)
Discussion started by: sachin.gangadha
3 Replies

10. Shell Programming and Scripting

Check for numeric inputs

Hi All, How do i modify the below script such that if the input is numeric, it will give the numeric digit, else it will ouput "0" echo "xxx" | awk '/^+$/' (6 Replies)
Discussion started by: Raynon
6 Replies
Login or Register to Ask a Question