conditional Testing numeric and text values problems


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting conditional Testing numeric and text values problems
# 1  
Old 06-01-2011
conditional Testing numeric and text values problems

hi, when i type in a value higher than 20 it will show me the validation but if i put a negative figure it just goes goes blank where i just keep typing and nothing happens so i had to control c to exit out the process, can someone help me please.

Code:
clear
        read -p "please enter professionalism score:" prof1
                echo -e "\n"
output=$(grep -w "$prof1" appraisalrecord)
output4=$(echo $prof1 | tr -dc '[:digit:]')
        if [[ $prof1 -gt 20 && $prof1 -le -1 ]]; then
                echo "please enter a score out of 20"
                     sleep 2
                     newrecord
        elif [[ "$prof1" = "$output4" ]]; then
                echo -e "$prof1 has been accepted\n"
                     sleep 2
        else
                echo "The input must be a numerical number"
                     sleep 2
                     newrecord
        fi

# 2  
Old 06-01-2011
There is something wrong i guess, how could you validate a value to be greater than 20 and less than -1 ?
Code:
if [[ $prof1 -gt 20 && $prof1 -le -1 ]];

# 3  
Old 06-01-2011
You are supplying an argument to grep which will cause it to print 20 lines before and after each match

To indicate that no further options are to be read, use the "--" end of options indicator
Code:
clear
        read -p "please enter professionalism score:" prof1
                echo -e "\n"
output=$(grep -w -- "$prof1" appraisalrecord)
output4=$(echo -- $prof1 | tr -dc '[:digit:]')
        if [[ $prof1 -gt 20 || $prof1 -le -1 ]]; then
                echo "please enter a score out of 20"
                     sleep 2
                     newrecord
        elif [[ "$prof1" = "$output4" ]]; then
                echo -e "$prof1 has been accepted\n"
                     sleep 2
        else
                echo "The input must be a numerical number"
                     sleep 2
                     newrecord
        fi


Last edited by Skrynesaver; 06-01-2011 at 07:16 AM.. Reason: Included fix for kumaran's observetion above
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Replace a numeric values in a certain column

Hi All, I am trying to replace a certain value from one place in a file . In the below file at position 35 I will have 8 I need to modify all 8 in that position to 7 I tried awk '{gsub("8","7",$35)}1' infile > outfile ----> not working sed -i 's/8/7'g' infile --- it is replacing all... (3 Replies)
Discussion started by: arunkumar_mca
3 Replies

2. UNIX for Advanced & Expert Users

Sort by second column numeric values

From googling and reading man pages I figured out this sorts the first column by numeric values. sort -g -k 1,1 Why does the -n option not work? The man pages were a bit confusing. And what if I want to sort the second column numerically? I haven't been able to figure that out. The file... (7 Replies)
Discussion started by: cokedude
7 Replies

3. Shell Programming and Scripting

Assigning numeric values to variable

I have a code like this v_num=9 comp_num=39 if then echo "pass" fi echo "end" I am getting an error ksh: v_num=99 comp_num=39 if then echo "pass" fi echo "end" (3 Replies)
Discussion started by: swayam123
3 Replies

4. UNIX for Dummies Questions & Answers

Only print lines with 3 numeric values

Hey guys & gals, I am hoping for some advice on a sed or awk command that will allow to only print lines from a file that contain 3 numeric values. From previous searches here I saw that ygemici used the sed command to remove lines containing more than 3 numeric values ; however how... (3 Replies)
Discussion started by: TAPE
3 Replies

5. Shell Programming and Scripting

how to grep only particular length of numeric values

hi i have two types of file 1. temp.0000000001.data (10 digit numeric) 2. temp.000000001.data (9 digit numeric) i want to search a file which is having 10 digit numeric in between the file name. i use command like this.. ls | grep temp.^*.data but this will give both the files as... (2 Replies)
Discussion started by: somi2yoga
2 Replies

6. Shell Programming and Scripting

How to check if the file contains only numeric values

How to check if the file contains only numeric values. I don't want to read entire file it eats lot of cpu Or any way which consumes less memory n cpu.. Please suggest -S (2 Replies)
Discussion started by: sunilmenhdiratt
2 Replies

7. Programming

numeric values ending in 'U'

I am getting back on the C++ programming after many years away. I recently received an SDK that has code like this where numeric values end in 'U'. What does this mean? if ((ptr % 16U) == 0U) return buffer; (3 Replies)
Discussion started by: sneakyimp
3 Replies

8. Shell Programming and Scripting

Remove non numeric values from a variable

Hello all, I am working on a basic script but need a little help. Issue: I am running a SQL Query using sqlplus and a shell script. I have the output of the statement stored as variable $A. $A is set to "other text here 45678754 other text here". I need to strip all text except that numeric... (13 Replies)
Discussion started by: ownedthawte
13 Replies

9. Shell Programming and Scripting

stripping out non-numeric values in a list

hi all, i'm very new to scripting and have the folllowing issue. I have used a few commands to get a list of numbers, but I need to strip away the non-numeric ones, and then need a total of all values. any ideas? root@unixserver # cat myfile | awk '{print $8}'| sort -rn 1504 1344 896 704... (2 Replies)
Discussion started by: badoshi
2 Replies

10. Shell Programming and Scripting

Replace spaces with 0's having numeric values.

What could be the regular expression with gsub function in awk to replace all numerics having spaces before to be replaced with 0s? (1 Reply)
Discussion started by: videsh77
1 Replies
Login or Register to Ask a Question