08-12-2009
FWIW -
perl and awk internally represent numbers as doubles. Most implementations have a limit set of DBL_DIG = 15.
Therefore having more than 15 digits in your output string (by forcing it with the format command like printf("%22.18", value) ) is going to give you garbage at some point in the number string.
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
Hi
I have the following file, how I will calculate the sum of all the entries in the file.
> cat abc
2
3
4
now the sum should be 2+3+4 = 9 (4 Replies)
Discussion started by: sdosanjh
4 Replies
2. Shell Programming and Scripting
Hello.
I face this (2 side) problem.
Some lines with this structure.
...........
12345678 4
12345989 13
12346356 205
12346644 74
12346819 22
.........
The first field (timestamp) is growing (or at least equal).
1)Sum the second fields if the first_field/500 are... (8 Replies)
Discussion started by: paolfili
8 Replies
3. Shell Programming and Scripting
Hi friends,
This is sed & awk type question.
I have a text file which has numbers spread all over the file. I want to sum the series of numbers whenever i find it and produce an output file with the sum. For example
###start of input text file ####
abc
def
ghi
1
2
3
4
kjld
random... (3 Replies)
Discussion started by: kaaliakahn
3 Replies
4. Shell Programming and Scripting
Hi friends,
This is sed & awk type question. It is slightly different from my previous question.
I have a text file which has numbers spread all over the file. I want to sum the series of numbers (but no more than 10 numbers in series) whenever i find it and produce an output file with the... (4 Replies)
Discussion started by: kaaliakahn
4 Replies
5. Shell Programming and Scripting
Hi,
I am using the following code to find the sum of the values of column 286 in a file. It will have the Decimal values with the scale of 2. Delimiter is '|^'
cut -d'|^' -f286 filename|cut -c3-| awk '{ x += $1 } END { printf("%.2f\n", x) }'
There are around 50k records in this file... (2 Replies)
Discussion started by: Jram
2 Replies
6. UNIX for Dummies Questions & Answers
Hello,
I am new to Linux environment , I working on Linux script which should send auto email based on the specific condition from log file. Below is the sample log file
Name m/c usage
abc xxx 10
abc xxx 20
abc xxx 5
xyz ... (6 Replies)
Discussion started by: asjaiswal
6 Replies
7. Shell Programming and Scripting
I ran this script:
#!/bin/bash
./disk-usage-JM.pl > jm_out
InFile="jm_out"
OutFile="jm_temp"
awk '{if (!match(" \t",substr($0,1,1))) {server=$0; next}
if (substr($0,1,1)==" ") {workspace=$0; next}
print server,workspace,$0}' \
$InFile >$OutFile
rm jm_out
against this... (2 Replies)
Discussion started by: master-of-puppe
2 Replies
8. Shell Programming and Scripting
I need to sum values in text file in case duplicate row are present with same name and different value below is example of data in file i have and format i need.
Data in text file
20170308
PM,U,2
PM,U,113
PM,I,123
DA,U,135
DA,I,113
DA,I,1
20170309
PM,U,2
PM,U,1
PM,I,123
PM,I,1... (3 Replies)
Discussion started by: Adfire
3 Replies
9. Shell Programming and Scripting
In the awk below I am trying to add a penalty to a score to each matching $1 in file2 based on the sum of $3+$4 (variable TL) from file1. Then the $4 value in file1 is divided by TL and multiplied by 100 (this valvue is variable S). Finally, $2 in file2 - S gives the updated $2 result in file2.... (2 Replies)
Discussion started by: cmccabe
2 Replies
10. UNIX for Beginners Questions & Answers
I have two files, file1.table is the count table, and the other is the range condition file2.range.
file1.table
chr start end count
N1 0 48 1
N1 48 181 2
N1 181 193 0
N1 193 326 2
N1 326 457 0
N1 457 471 1
N1 471 590 2
N1 590 604 1
N1 604 752 1
N1 752 875 1
file2.range... (12 Replies)
Discussion started by: yifangt
12 Replies
ecvt(3C) Standard C Library Functions ecvt(3C)
NAME
ecvt, fcvt, gcvt - convert floating-point number to string
SYNOPSIS
#include <stdlib.h>
char *ecvt(double value, int ndigit, int *restrict decpt, int *restrict sign);
char *fcvt(double value, int ndigit, int *restrict decpt, int *restrict sign);
char *gcvt(double value, int ndigit, char *buf);
DESCRIPTION
The ecvt(), fcvt() and gcvt() functions convert floating-point numbers to null-terminated strings.
ecvt()
The ecvt() function converts value to a null-terminated string of ndigit digits (where ndigit is reduced to an unspecified limit determined
by the precision of a double) and returns a pointer to the string. The high-order digit is non-zero, unless the value is 0. The low-order
digit is rounded. The position of the radix character relative to the beginning of the string is stored in the integer pointed to by decpt
(negative means to the left of the returned digits). The radix character is not included in the returned string. If the sign of the result
is negative, the integer pointed to by sign is non-zero, otherwise it is 0.
If the converted value is out of range or is not representable, the contents of the returned string are unspecified.
fcvt()
The fcvt() function is identical to ecvt() except that ndigit specifies the number of digits desired after the radix point. The total num-
ber of digits in the result string is restricted to an unspecified limit as determined by the precision of a double.
gcvt()
The gcvt() function converts value to a null-terminated string (similar to that of the %g format of printf(3C)) in the array pointed to by
buf and returns buf. It produces ndigit significant digits (limited to an unspecified value determined by the precision of a double) in %f
if possible, or %e (scientific notation) otherwise. A minus sign is included in the returned string if value is less than 0. A radix
character is included in the returned string if value is not a whole number. Trailing zeros are suppressed where value is not a whole num-
ber. The radix character is determined by the current locale. If setlocale(3C) has not been called successfully, the default locale,
POSIX, is used. The default locale specifies a period (.) as the radix character. The LC_NUMERIC category determines the value of the
radix character within the current locale.
RETURN VALUES
The ecvt() and fcvt() functions return a pointer to a null-terminated string of digits.
The gcvt() function returns buf.
ERRORS
No errors are defined.
USAGE
The return values from ecvt() and fcvt() might point to thread-specific data that can be overwritten by subsequent calls to these functions
by the same thread.
For portability to implementations conforming to earlier versions of Solaris, sprintf(3C) is preferred over this function.
ATTRIBUTES
See attributes(5) for descriptions of the following attributes:
+-----------------------------+-----------------------------+
| ATTRIBUTE TYPE | ATTRIBUTE VALUE |
+-----------------------------+-----------------------------+
|Interface Stability |Standard |
+-----------------------------+-----------------------------+
|MT-Level |Safe |
+-----------------------------+-----------------------------+
SEE ALSO
printf(3C), setlocale(3C), sprintf(3C), attributes(5), standards(5)
SunOS 5.10 18 May 2004 ecvt(3C)