Sponsored Content
Top Forums UNIX for Dummies Questions & Answers check if a decimal number is greater than zero Post 302557650 by fpmurphy on Wednesday 21st of September 2011 08:54:45 PM
Old 09-21-2011
Quote:
[ ${a%%.*} -gt 0 ] && echo "ok" || echo "wrong"
This test will fail where a < 1.

Quote:
Unless you're using a really new ksh, numeric comparison doesn't work on numbers with decimal points.
Huh? Floating point support, what you call numbers with decimal points, has been available in ksh93 since 1993.

If you want to do floating point arithmetic from within a bash script, you need to use an external utility such as bc. See Floating Point Math in Bash
 

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Show result only if number is greater then

Hello all Im trying to write one liner that will show me results only if the result of the expression is greater then 0 For example: I do : find . -name "*.dsp" | xargs grep -c SecurityHandler the result are : ./foo/blah/a.dsp:0 ./foo/blah1/b.dsp:1 ./foo/blah2/c.dsp:2... (1 Reply)
Discussion started by: umen
1 Replies

2. Shell Programming and Scripting

Check numeric fields greater than zero, and delete lines if appropriate

This be the latest in my problems sorting through router logs... I'm half way there on a problem, but I've hit the limitation of my knowledge Got some router interface log files of type router01:GigabitEthernet9/24 is up, line protocol is up (connected) router01: 0 input errors, 0 CRC, 0... (7 Replies)
Discussion started by: Yorkie99
7 Replies

3. Shell Programming and Scripting

[Solved] Select the columns which have value greater than particular number

i have a file of the form 9488 14392 1 1.8586e-07 5702 7729 1 1.8586e-07 9048 14018 1 1.8586e-07 5992 12556 1 1.8586e-07 9488 14393 1 1.8586e-07 9048 14019 1 1.8586e-07 5992 12557 1 1.8586e-07 9488 14394 ... (1 Reply)
Discussion started by: vaibhavkorde
1 Replies

4. Shell Programming and Scripting

AWK: Cannot read Number of records greater than 1(NR>1)

Hi all, I have a tab-delimited text file of size 10Mb. I am trying to count the number of lines using, grep -c . sample.txtor wc -l < sample.txt or awk 'END {print NR}' sample.txtAll these commands shows the count as 1, which means they are reading only the first header line of the file.... (3 Replies)
Discussion started by: mehar
3 Replies

5. Shell Programming and Scripting

Need to check the value greater than or less than and give out put to a file

HI, I have one file which is as below cat /var/tmp/test1 | awk '{ print $3}'|grep -v affected Data ---------- 200.4 . The above 200 value is changable by the database script. Now I need a script that checks the value 200.4 and the script shoud give out put if value is more than 225 (2 Replies)
Discussion started by: phani4u
2 Replies

6. Shell Programming and Scripting

Egrep a greater than number

data: hello mr smith 400 you all ok? hello mrs. smith 700 you all ok? hello mr. everyone 150 you all ok? hello mr. you all 199 im lad you are ok using egrep, how can i grep out only lines that have a number greater than 250? cat data | egrep ..... can't use awk here. i was... (7 Replies)
Discussion started by: SkySmart
7 Replies

7. Shell Programming and Scripting

Egrep a number greater than in a column

i'm aware awk can do what i'm trying to do here. but i cant use awk in this scenario given the circumstance of this box. but i need to check if a number is a certain column is over a certain value, say for instance, 20. data: | 12 | 19 | 2000 | 9029333 |... (11 Replies)
Discussion started by: SkySmart
11 Replies

8. Shell Programming and Scripting

Grep lines for number greater than given number

Hello, I am newbie to bash scripting. Could someone help me with the following. I have log file with output as shown below **************************LOG************************* 11/20/2013 9:11:23.64 Pinging xx.xx.xx.xx with 32 bytes of data: 11/20/2013 9:11:23.64 Reply from xx.xx.xx.xx:... (4 Replies)
Discussion started by: meena_2013
4 Replies

9. UNIX for Dummies Questions & Answers

Greater than specific number

please let me know how to construct if then else by comparing two numbers if it is greater than 10000. I need to do some specific task executed. can you help me out in shell scripting plz. (6 Replies)
Discussion started by: ramkumar15
6 Replies
nextafterd64(3M)														  nextafterd64(3M)

NAME
nextafterd64(), nextafterd128(), nextafterd32(), nexttowardd64(), nexttowardd128(), nexttowardd32() - next representable decimal floating- point numbers SYNOPSIS
DESCRIPTION
The function computes the next representable number following x in the direction toward y. Thus, if y is less than x, returns the largest representable number less than x. The function returns y if x equals y. The function is equivalent to except that the second parameter has the widest decimal floating-point type, and the function returns y con- verted to the type of the function if x equals y. The result of the function is determined in the type of the function, without loss of range or precision in a floating second argument, whose type may be wider than the type of the function. is a version of it takes arguments and returns a result. is a version of it takes arguments and returns a result. is a version of it takes a first argument and returns a result. is a version of it takes a first argument and returns a result. These math functions are supported for HP-UX 11i Version 3 September 2008 Update and forward. USAGE
To use any of these functions, compile with the option. Make sure your program defines and then includes Link in the math library by specifying or on the linking command line. For more information, see the at the following site: RETURN VALUE
If x equals y, returns y, and returns y converted to the type of x. If x is finite and the correct function value would overflow, these functions return according to the sign of x, and raise the overflow and inexact floating-point exceptions. If the return value is subnormal and x!=y, these functions raise the underflow and inexact floating-point exceptions. If x or y is NaN, these functions return NaN. ERRORS
If x is finite and the correct function value would overflow, these functions set to SEE ALSO
scalbnd64(3M), math(5). STANDARDS CONFORMANCE
These functions conform to ISO/IEC TR 24732, "Extension for the programming language C to support decimal floating-point arithmetic". HP Integrity Server Only nextafterd64(3M)
All times are GMT -4. The time now is 06:39 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy