Conversion of Exponential to numeric in awk- not correct output


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Conversion of Exponential to numeric in awk- not correct output
# 1  
Old 04-24-2008
Conversion of Exponential to numeric in awk- not correct output

Hi All,

I have 1 million records file. Using awk, I am counting the number of records. But as the number is huge, after crossing a number, awk is displaying it in exponential format.

At the end, I need to verify this count given by awk with expected count.
But as it is in exponential format, the comparision is failing.

I tried converting the exponential format to numeric using printf("%d,$0) formats , but when converting it is not giving the accurate value.

Say I have 10,93,861 records in the file. Awk is giving following output -> 1.09386e+06

When converting this exponential format to numeric, it is giving the value as10,93,860 which is incorrect.

I dont want to implement this in shell as it takes huge amount of time for the file.

Please help.
Regards,
Ssunda.
# 2  
Old 04-24-2008
You shouldn't use awk if you only need the record count of a file. Use "wc -l filename.txt" instead.

Otherwise, if you make some computations in the awk code, I think that knowing which version of awk on which OS are you using will give us some more info for solving the issue.
# 3  
Old 04-24-2008
I am not just taking the count of records. In addition to that I am also doign some processing and validations.

I tried to check the version of awk using
awk -v and
awk --version

but is displaying usage of awk only.

OS is Unix

Regards,
ssunda.
# 4  
Old 09-19-2008
Hi ssunda6,

Could you tell me how u handled this issues.

Thanks in Advance.

Regards,
Sreekanth
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk output is not the correct count

The awk below runs and produces the following output on the file2. This is just an example of the format as the file is ~14MB. file1.txt is attached. I am trying to count the ids that match between the two files and out the ids that are missing. Thank you :). file2 970 NM_213590 ... (2 Replies)
Discussion started by: cmccabe
2 Replies

2. Shell Programming and Scripting

Awk-Exponential Values

Hi Friends, My input Gene1 4.14887050399078e-49 Gene2 5.39999891278828e-10 Gene 2.22108326729483e-11 How do I change the above exponential values to normal values? Thanks (3 Replies)
Discussion started by: jacobs.smith
3 Replies

3. Shell Programming and Scripting

Help with sort word followed by exponential number and numeric number at the same time

Input file: ID_34 2E-69 2324 ID_1 0E0 3254 ID_1 0E0 5434 ID_5 0E0 436 ID_1 1E-14 2524 ID_1 5E-52 46437 ID_3 65E-20 45467 ID_1 0E0 6578 ... Desired output file: ID_1 0E0 6578 ID_1 0E0 5434 ID_1 0E0 3254 ID_1 5E-52 46437 ID_1 1E-14 2524 ID_3 65E-20 45467 (5 Replies)
Discussion started by: cpp_beginner
5 Replies

4. Shell Programming and Scripting

AWK - Avoid exponential value

I'm using the following command, but how can I avoid printing exponential value (highlighted):- awk ' BEGIN { OFS=FS="|" } { if(NF>4) $10=int(((3.77*$11)/100 + $11)); } { print } ' infile CR|20121022|105|GSM|N|SAN|00122|SAN|75082|6.03929e+06|5819880|5794769|25111... (7 Replies)
Discussion started by: Yoda
7 Replies

5. Shell Programming and Scripting

String variable to numeric conversion in perl

Hi guys I am having this strange issue.Well my requirement is like below Compare two values between flat file and oracle DB Via perl script I am easily getting the rowcount Now I connect sql plus via perl and the column value that returns is string my $sqlplus_settings = ''; my... (7 Replies)
Discussion started by: Pratik4891
7 Replies

6. UNIX for Advanced & Expert Users

Date Conversion on output string from awk

Hi, I would like to convert the output from awk function to date and print on the screen. Example : echo "Start Date: May 24 2010" | gawk -F": " '{print $2}' Output : May 04 2010 I want this to be converted to 2010/05/24 Can i use date function here and how? Thanks, Deepika (2 Replies)
Discussion started by: deepikad
2 Replies

7. Shell Programming and Scripting

script for month conversion in numeric format

Hi Experts, How to convert months into numeric format with the help of some script: Suppose I want: " Jan | Feb | Mar | Apr | May | Jun | Jul | Aug | Sept | Oct | Nov | Dec " to be converted as : " 01 | 02 | 03 | 04 | 05 | 06 | 07 | 08 | 09 | 10 | 11 | 12 " Thanks in... (2 Replies)
Discussion started by: rveri
2 Replies

8. Shell Programming and Scripting

AWK: Discrepancy in numeric output

During a file-system cleanup I noticed a strange behavior of awk (HP-UX 11iv3 / IA64). When summing up the size of files in one directory it gives different numbers when using print as opposed to printf: find . -type f -name '*.dmp.Z' -mtime +35 -exec ls -l {} \+ | \ awk 'BEGIN{ OFMT="%f" } {... (1 Reply)
Discussion started by: pludi
1 Replies

9. Shell Programming and Scripting

AWK not giving me correct output.

i have a line like this in my script IP=`get_IP <hostname> | awk '{ print $1 }' echo $IP the problem is get_IP <hostname> returns data formated as follows: ip 1.1.1.1 name server_name the code above returns 1.1.1.1 server_name and i just need the 1.1.1.1 I have tried to add "|... (5 Replies)
Discussion started by: mcdef
5 Replies

10. Shell Programming and Scripting

:-) 1213: Character to numeric conversion error. Plz help

Dear friends, I am new to Unix/Linux. I am trying to run following query but getting an error msg... Please can u people help me in this? Query: echo "select status_ac from db_acct where acct_num=AAA000337" | dbaccess elstest Error: 217: Column (amd000337) not found in any table in the... (2 Replies)
Discussion started by: anushree.a
2 Replies
Login or Register to Ask a Question