How to declare float in shellscript?

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to declare float in shellscript?
# 1  
Old 09-28-2011
How to declare float in shellscript?

Hi All,

I am having an abc.txt , which contains some digits



I want write shellscript in suchway that if any digit is greter than 90 then it shuld display " digit is greater than 90"

Please help me to do so .I have tried below code , for integer the below code is working fine . if the abc.txt file contain float values then its not workin properly.

#! /bin/bash
for i in `cat abc.txt`
if [ $i -gt $b ] ; then
echo " value is greater than $b "

please help me for the float values

# 2  
Old 09-28-2011
$ nawk '{if($0>90){print $0" is greater than 90"}else{print $0" is less than 90"}}' test
14.5 is less than 90
56.6 is less than 90
95.5 is greater than 90

# 3  
Old 09-28-2011
hi itkamraj,

Tried the below code
nawk '{if($0>90){print $0" is greater than 90"}else{print $0" is less than 90"}}' abc.txt

getting below error

-bash: nawk: command not found

I think nawk is not working on my server
# 4  
Old 09-28-2011
$ perl -lane 'print $_ if($_ > 90)' test

---------- Post updated at 12:47 PM ---------- Previous update was at 12:46 PM ----------

use awk instead of nawk
# 5  
Old 09-28-2011


Try this code,

if [ $(echo "$i > $b"|bc) -eq 1 ]
instead of below code
if [ $i -gt $b ] ; then

This User Gave Thanks to rangarasan For This Post:
# 6  
Old 09-28-2011
If you really want to do the test from within a shell script without the need to call an external utility such as awk or perl, you need to use a shell that supports floating point i.e. ksh93 or zsh. Bash is quite a rudimentary shell. Among other limitations, it does not support floating point.



while read i
   if (( i > b ))
      echo " value is greater than $b "
done < abc.txt

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

Declare member of struct as a pointer in c

I have a uint8_t *C = malloc(24*sizeof(uint8_t)); I need to send some integers and this *C to another node(in ad hoc network). So I am going to use a struct ` struct fulMsg { int msgType; int msgCount; //uint8_t *CC; } fulMsg_t; typedef struct fulMsg fulMsg_tt;` there is a method... (1 Reply)
Discussion started by: chap
1 Replies

2. Shell Programming and Scripting

how to declare variable in perl

how can i declare variable in perl. for BLOCK in /sys/block/emcpow* (3 Replies)
Discussion started by: learnbash
3 Replies

3. UNIX for Dummies Questions & Answers

How do I declare boost?

Hello all, I am trying to "make" a database system, VDB (Veritas Data Base), and when I run "make" I receive the following error: VDBException.h:19: error: expected `)' before '*' token VDBException.h:20: error: expected `)' before '*' token VDBException.h:43: error: expected `)' before '*'... (4 Replies)
Discussion started by: Tyler_92
4 Replies

4. UNIX for Dummies Questions & Answers

declare variable

hi to all, i am trying to declare a variable as an integer in unix shell script. i search the web for a way to do it but it doesnt work. i tried "define -i" and "declare" but that doesnt work. if somebody knows another way to declare a variable as integer please help me. thank you (2 Replies)
Discussion started by: omonoiatis9
2 Replies

5. Programming

declare a variable in mysql

i have created a script to insert 100K rows into mysql db. But the forst line where i declare the variable is giving error. I am new to mysql. Can anyone help me in this? the script is ====================================== DECLARE c INT(10) := 54; BEGIN WHILE c <... (4 Replies)
Discussion started by: amitranjansahu
4 Replies

6. Shell Programming and Scripting

BASH : Using declare in a loop

I have a config file that needs to be formatted before it's sourced to a script. I've been formatting it with sed and dropping it in /tmp then sourcing it from there. I'd like to just format the config file with sed then declare the variables without having to create a temporary file in /tmp. So... (2 Replies)
Discussion started by: crs6785
2 Replies

7. Shell Programming and Scripting

How to declare an array to take more than 10,000 characters

Hi Guys Need some help I am reading the string values from the text files into the shell script and had them feed into array I have declared an associative array as TYPE t_user_id_tab IS TABLE OF VARCHAR2(3000);\n my_user_id t_user_id_tab;\n varchar2 is limiting me to take only... (0 Replies)
Discussion started by: pinky
0 Replies

8. Programming

math.h: float ceilf(float x)

Good morning, I'm testing the use of ceilf: /*Filename: str.c*/ #include <stdio.h> #include <math.h> int main (void) { float ceilf(float x); int dev=3, result=0; float tmp = 3.444f; printf("Result: %f\n",ceilf(tmp)); return 0; } (1 Reply)
Discussion started by: jonas.gabriel
1 Replies

9. UNIX for Dummies Questions & Answers

can unix program declare int?

can unix program declare int??how to declare ? if i want to declare int and using read command then compare which int is to do this??can somebody help me? (1 Reply)
Discussion started by: yeah016
1 Replies

10. Programming

File declare !

Dear all I declare like this in my program : int main(int argc ,char **argv) { FILE *ft; char* ini_file; char fbuf; char sendbuf; char strbuf; } When I compile this is the error : cc: "send.c", line 28: error 1588: "ft" undefined. (1 Reply)
Discussion started by: iwbasts
1 Replies
Login or Register to Ask a Question