Text data string conversion to Integer


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Text data string conversion to Integer
# 1  
Old 07-19-2009
Text data string conversion to Integer

Folks
Appreciate your help in understanding issue in relation to below.
I need to pul uvalue from a file (tmpfile) and compare it with a number to make decision.

Using #!/bin/sh
contents of tmpfile :
Slot uvalue : 0.16 [%]

How I am pulling it:
unifval=`awk '/uvalue/ {print $4}' tmpfile`

when I try below if statements to compare this uvalue to a number it does not work.
if test $unifval -gt 0.1
#if [ $unifval > 0.20 ] #tried this too but did not work.

Could you please help me.. thanks in advance

Last edited by wndgs; 07-19-2009 at 12:46 PM..
# 2  
Old 07-19-2009
Bash, ksh88, bourneshell, .. not understanding float numbers.
But ksh99 understand, also test
Code:
typeset -F2 num1 num2 num3
num1=1.22 
num2=2.22 
(( num3=num1*num2)) 
echo $num3 
# or using printf
test  $num3 -lt $num1 
#and 
[ $num3 -lt $num1 ]
# are same builtin command

Or use bc, works with every shell and it's Calculator.
Code:
result=$( echo "1.12 + 2.11" | bc  )
result=$( echo "1.12 < 2.11" | bc  )
# give output 1
# and
result=$( echo "1.12 > 2.11" | bc  )
# give output 0

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to read all data after a specific string from a text file ?

Hi, I have a file(input.txt) and trying to format as output.txt. See the attached file format. Note: This is a windows file (DOS format) and the commands are also going to execute on windows. Basically I am trying to capture all the data in between Local Group Memberships and Global Group... (10 Replies)
Discussion started by: Monoj2014
10 Replies

2. Shell Programming and Scripting

String to integer

I am on HP-UX using ksh in the script. MaxSal=`sqlplus -silent /nolog <<EOF connect / as sysdba whenever sqlerror exit sql.sqlcode set pagesize 0 feedback off verify off heading off echo off select max(sal) from emp1; select max(sal) from emp2; select max(sal) from emp3; exit; EOF`... (3 Replies)
Discussion started by: bang_dba
3 Replies

3. Shell Programming and Scripting

how to compare string integer with an integer?

hi, how to I do this? i="4.000" if ; then echo "smaller" fi how do I convert the "4.000" to 4? Thanks! (4 Replies)
Discussion started by: h0ujun
4 Replies

4. Shell Programming and Scripting

find string(s) in text file and nearby data, export to list help

Hi, So I'm kinda new to shell scripts and the like. I've picked up quite a bit of use from browsing the forums here but ran into a new one that I can't seem to find an answer for. I'm looking to parse/find a string AND the next 15 or so charachters that follow the string within a text file... (1 Reply)
Discussion started by: kar23me
1 Replies

5. Shell Programming and Scripting

Searching for a particular string and modifying text within block of data

Hi Forum. Is there a quick way to do the following search/replace within a block of data? I tried to google the solution but didn't really know what to look for. I have the following text file (I want to search for a particular string "s_m_f_acct_txn_daily_a1" and replace the... (5 Replies)
Discussion started by: pchang
5 Replies

6. UNIX for Dummies Questions & Answers

integer to string

Hi all, is there an easy way to convert integer to string in bash? I have numbers like 1, 2, ..., 112, ... and I would like to get 001 002 003 004 ... Thank you, Sarah (4 Replies)
Discussion started by: f_o_555
4 Replies

7. Shell Programming and Scripting

extracting integer from data

Hi people, I've encountered a problem. I have a data file like: asd:$123:2 zxc:$456:4 But when I want to extract "$123" and get the number with this command: echo $123 | cut -c 1-10 Im returned with 23 instead of 123. Please help me out, thanks. (4 Replies)
Discussion started by: grotesque
4 Replies

8. UNIX for Dummies Questions & Answers

Binary data to text file conversion

Dear Sir; i want to know how the binary data convert to text file or readablw format (ASCII).If possible pl. help me for the software and where it is available for download. i.e. (1 Reply)
Discussion started by: auro123
1 Replies

9. Shell Programming and Scripting

conversion to integer not working

Hello.. I have a file containg as below: My need is to sum the values... but the error is showing as interger conversion..so i put int() but again not working..please help..here is my code Thanks in advance esham (7 Replies)
Discussion started by: esham
7 Replies

10. Programming

Integer to String

Which function should I use to convert an Integer to a String or Char format ? Thanx (2 Replies)
Discussion started by: psilva
2 Replies
Login or Register to Ask a Question