Problem with format numbers


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Problem with format numbers
# 1  
Old 04-08-2011
Problem with format numbers

Hello Everyone!

I hope you can help me!!

I have this little problem:

I executed oracle query and the output of the result are in a text file called "DATAFILE.txt", and the value of file is: 97.37

Well, the script compare the result in text file with a condition:

Code:
PORCENTAJE_DATAFILE_USED=$(cat DATAFILE.txt)
if [ $PORCENTAJE_DATAFILE_USED -ge 99.6 ]
then
        echo "DATAFILE SIZE WARNING"
fi

The output result is:
Code:
[: 8: Illegal number: 97.37

I think, the condition take the value 97.37 like a string and not like decimal number.

I don't know hoy I can convert de value in decimal.

Can you help me?
# 2  
Old 04-08-2011
Code:
awk '$1 > 99.6{print "DATAFILE SIZE WARNING"}' file

# 3  
Old 04-08-2011
Quote:
Originally Posted by kato
Code:
awk '$1 > 99.6{print "DATAFILE SIZE WARNING"}' file

Thanks a lot kato!!!
# 4  
Old 05-11-2011
Hi friends,
I am also facing similar kind of issue. pls provide me the solution.

Data is as follows:
Code:
 
13143184587         50020110503N+00000712402011050120110507+004000+000000000000000000

Code :
Code:
 
     echo "$line" | awk ' {print substr($0,1,1) ","   substr($0,2,19) ","   substr($0,21,1) ","   substr($0,24,8) ","   substr($0,32,1) ","   substr($0,33,11) ","   substr($0,44,8) ","   substr($0,52,8) ","   substr($0,60,7) ","   substr($0,67,7) ","   substr($0,74,2) ","   substr($0,76,8) ","   substr($0,84,2) ","   substr($0,86,20) ","   substr($0,106,20) ","   substr($0,126,15) ","   substr($0,141,8) } ' >>  pmt_data.csv

substr($0,33,11) --> will give the amount field.
My final out put for this column should be 712.40
# 5  
Old 05-15-2011
If you want to test your amount and then print the formatted line if it passes the test, try:

Code:
awk '{a=substr($0,33,11); line=substr($0,1,1) "," substr($0,2,19); if(a>712.40) print line}' file

Please note, I have not replicated your entire substr() sequence for clarity, so just add it as required.
# 6  
Old 05-15-2011
You can make use of bc also

Code:
#!/bin/bash
PORCENTAJE_DATAFILE_USED=$(cat DATAFILE.txt)
ret=$(echo "$PORCENTAJE_DATAFILE_USED >= 99.6" | bc)
if [ $ret -eq 1 ];then echo "DATAFILE SIZE WARNING"; fi

regards,
Ahamed
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Awk: Wondering how to format numbers with comma

I have tried the following commands and can't get a number to format with commas: echo 1234567.12 |awk '{printf("%-12s %20s\n", $0, comma($0)) }' This prints out value 50000 without a comma for i in *13*; do (cd $i && du -sk . && echo $i);done|grep -v 0000|gawk -F OFS="," ' {SUM += $1}... (8 Replies)
Discussion started by: newbie2010
8 Replies

2. Shell Programming and Scripting

Problem with numbers in exponential format

Hi I have a shell scribt with some numbers in exponential format, for example, "1.23456789E +01" Now I would like to bring these numbers into a format without the E. Can someone help me Thanks Flo ---------- Post updated at 10:07 AM ---------- Previous update was at 09:14 AM... (1 Reply)
Discussion started by: sbfly
1 Replies

3. UNIX for Dummies Questions & Answers

Magic numbers string/B problem

Hello, In manpage magic(5) " The “B” flag compacts whitespace in the target, which must contain at least one whitespace character. If the magic has n consecutive blanks, the target needs at least n consecutive blanks to match. The “b” flag treats every blank in the target as an optional... (4 Replies)
Discussion started by: segmentation
4 Replies

4. UNIX for Dummies Questions & Answers

Magic numbers '&' operator problem

Hello everyone, on the man page of "magic(5)" There is explanation "&, to specify that the value from the file must have set all of the bits that are set in the specified value" . My question is that what is the difference between '&' and equal operator '=' ? I tested it with file... (6 Replies)
Discussion started by: segmentation
6 Replies

5. UNIX for Dummies Questions & Answers

Problem with ranges of numbers

Good day to everyone! So, let's start :) I have a file with a numbers in some ranges for example: 1 10 49 72 ... and this file need to transform to: 1 2 3 4 (14 Replies)
Discussion started by: shizik
14 Replies

6. Shell Programming and Scripting

Problem with sub command (awk) and numbers

Hi, I am trying to perform a simple soustraction between two floating numbers and cannot get it done for some reason due to the use of the sub command. The following is the straight-forward result of the soustraction: $ echo | gawk '{a=968;b=967.99;c=a-b;print c}' ... (2 Replies)
Discussion started by: Indalecio
2 Replies

7. Shell Programming and Scripting

Format problem

can any one know that how can i get perfect format of phone number my function is phone_number=`echo $name_number | awk '{print $NF}'` check=`echo $phone_number | egrep -c "--"` i get the format but if i need perfect format like xxx-xxx-xxxx. if i enter not in this format it still... (1 Reply)
Discussion started by: tarunsavalia
1 Replies

8. Shell Programming and Scripting

grep or awk problem, unable to extract numbers

Hi, I've trouble getting some numbers from a html-file. The thing is that I have several html-logs that contains lines like this: nerdnerd, how_old_r_u:45782<br>APPLY: <hour_second> Verification succeded This is some of what I've extracted from a html file but all I really want is the number... (7 Replies)
Discussion started by: baghera
7 Replies

9. Programming

format problem

hey everyone, Im making a program that prints different patterns using * like this: * *** ***** ******* ***** *** * i am letting the user decide what the number of rows can be, i want the shape to appear on the left (60 spaces from the right) if it is even and on... (5 Replies)
Discussion started by: bebop1111116
5 Replies

10. Shell Programming and Scripting

problem with floating point numbers in awk

hi all, i have the following problem using awk in a script i want to read the values from a column with real numbers and calculate the mean.the problem is that when i use a statement such as this num = $4 i cant find a way to convert the variable from string to floating point to perform... (7 Replies)
Discussion started by: kanagias
7 Replies
Login or Register to Ask a Question