Sponsored Content
Top Forums Shell Programming and Scripting problem with AWK and floats below 0 Post 302298282 by JCastro on Tuesday 17th of March 2009 06:51:57 AM
Old 03-17-2009
problem with AWK and floats below 0

Hello. I have a problem with AWK and floats below 0 in a script.
It may be simplified to this line (please, take into account that my "locale" is Spanish, so the system will read "," as decimal separator):

Code:
echo -1,25 2,55745 0,33 ,278 | awk '{print $1+1, $2+1, $3+1, $4+1}'

... getting:
Code:
-0,25 3,55745 1 1

So, what about the third and fourth fields? Why do you think AWK is not reading correctly?

I have tried different options (also with printf options), but I am always at the same point: if the number is 0,xxx AWK will not read the decimal part.
Thank you very much in advance,
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Multiplying Floats/Decimals

Is there a way that i can get something like this to work: Number=`expr 80 \* 10.69` i.e. To multiply an integer by a decimal or a decimal by a decimal etc...? thanks (10 Replies)
Discussion started by: rleebife
10 Replies

2. Shell Programming and Scripting

integers, floats and text

I am using gawk in a dos shell in windows xp and want to read a datafile and reformat it. The datafile consists of columns of integers, floating point numbers and text strings. Each column is a fixed width and each column contains the same data type, eg all integers, all text. I am looking for a... (0 Replies)
Discussion started by: lookingfor help
0 Replies

3. Shell Programming and Scripting

awk problem

I want to assign the file name under my dir and store into variable fileName here is my for loop but awk seems doesn't work numberFile=`ls -l $dir | wc -l` for i in $numberFiles do fileName=` ls -l | awk `{print $8}`` blablabla done thanks for helping (4 Replies)
Discussion started by: cryogen
4 Replies

4. Shell Programming and Scripting

Awk problem: How to express the single quote(') by using awk print function

Actually I got a list of file end with *.txt I want to use the same command apply to all the *.txt Thus I try to find out the fastest way to write those same command in a script and then want to let them run automatics. For example: I got the file below: file1.txt file2.txt file3.txt... (4 Replies)
Discussion started by: patrick87
4 Replies

5. UNIX for Dummies Questions & Answers

awk problem

Hi, I obtain a error to execute this code: nawk -F¤ -v campotipo=${CAMPO_TIPO_SEDRA} ficherolog=${DIRECTORIO_LOGS_MARINE_SEDRA}/${F_LOG_SEDRA} -v ficheroerroneos=${LOG_SEDRA_ERRONEOS} -v separador=${SEPARADOR} -v num_campos=${NUMERO_CAMPOS} -v fichero_procesando=${FICHERO_ENTRADA} ' BEGIN { OFS... (2 Replies)
Discussion started by: danietepa
2 Replies

6. Shell Programming and Scripting

Problem with awk awk: program limit exceeded: sprintf buffer size=1020

Hi I have many problems with a script. I have a script that formats a text file but always prints the same error when i try to execute it The code is that: { if (NF==17){ print $0 }else{ fields=NF; all=$0; while... (2 Replies)
Discussion started by: fate
2 Replies

7. Shell Programming and Scripting

Calculation with floats

I want to make computations using floats. This cannot be done with csh. ksh seem to have a problem as well. What is good shell for computations without having to resort to bc or awk? How about python? (5 Replies)
Discussion started by: kristinu
5 Replies

8. Shell Programming and Scripting

awk problem - combining awk statements

i have a datafile that has several lines that look like this: 2,dataflow,Sun Mar 17 16:50:01 2013,1363539001,2990,excelsheet,660,mortar,660,4 using the following command: awk -F, '{$3=strftime("%a %b %d %T %Y,%s",$3)}1' OFS=, $DATAFILE | egrep -v "\-OLDISSUES," | ${AWK} "/${MONTH} ${DAY}... (7 Replies)
Discussion started by: SkySmart
7 Replies

9. Programming

Extracting floats from a string in Python

I have this script which can calculate the total of numbers given in a string total = 0 for c in '0123456789': total += int(c) print total How should I modify this script to find the total of if the numbers given in the string form have decimal places? That is, how do I need to modify... (2 Replies)
Discussion started by: faizlo
2 Replies

10. Shell Programming and Scripting

Awk-if problem

Hi This's my problem ( AIX ) switchshow | awk ' { if ( $1==0 ) print $0; }'It works But these below doesn't switchshow | awk ' { if ( $1==0 1 2 3 4 7 9 12 15 ) print $0; }'switchshow | awk ' { if ( $1== 7 9 12 15 ) print $0; }'Somebody help, please :(:(:( (3 Replies)
Discussion started by: bobochacha29
3 Replies
REMQUO(3)						   BSD Library Functions Manual 						 REMQUO(3)

NAME
remquo -- floating-point remainder and quotient function SYNOPSIS
#include <math.h> double remquo(double x, double y, int *quo); long double remquol(long double x, long double y, int *quo); float remquof(float x, float y, int *quo); DESCRIPTION
The remquo() functions compute the value r such that r = x - n*y, where n is the integer nearest the exact value of x/y. If there are two integers closest to x/y, n shall be the even one. If r is zero, it is given the same sign as x. This is the same value that is returned by the remainder() function. remquo() also calculates the lower seven bits of the integral quotient x/y, and gives that value the same sign as x/y. It stores this signed value in the object pointed to by quo. SPECIAL VALUES
remquo(x, y, quo) returns a NaN and raises the "invalid" floating-point exception if x is infinite or y is 0. VECTOR OPERATIONS
If you need to apply the remquo() function to SIMD vectors or arrays, using the following functions provided by the Accelerate.framework may give significantly better performance: #include <Accelerate/Accelerate.h> vFloat vremquo(vFloat x, vFloat y, vUInt32 *q); SEE ALSO
math(3), remainder(3) STANDARDS
The remquo() functions conform to ISO/IEC 9899:2011. BSD
December 11, 2006 BSD
All times are GMT -4. The time now is 01:18 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy