The awk subtraction giving exponential values.Please help resolve it


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting The awk subtraction giving exponential values.Please help resolve it
# 1  
Old 03-06-2011
The awk subtraction giving exponential values.Please help resolve it

Hi friends,
I have a file list1 which has these 2 columns like
Code:
616449 0
434453 1
2151083 0
2226536 0
2132382 0
2136814 0

I have to put the result of col1 -col2 into another file list2 linewise.

e.g. It gives the below result if use the below code:
Code:
awk '{ print $1 - $2 }' list1 > list2

616449
434453
2.15108e+06 
2.22654e+06 
2.13238e+06 
2.13681e+06

I don't want the exponential values Smilie
The problem with my code is that it turns the subtraction result into exponential for values greater than 6 digits. How should i modify the awk command (using some formatting features...i tried it but no success) to get the result in the format like given below
Code:
616449
434453
2151083
2226536 
2132382
2136814

Also if i try to convert the above exponential values to integer i use some values like 2.15108e+06 becomes 2151080 instead of required 2151083.


For now i have used the below workaround ,
But can anyone please tell me how to modify my above awk syntax to achieve it.
Code:
while read line
 do
 var1=`echo $line | awk '{ print $1}'`
 var2=`echo $line | awk '{ print $2}'`
 y=`expr $var1 - $var2`
 echo $y >> list2
done < list1

I have searched this forum number of times for this ,but no success still.Smilie


Regds,
Kunwar

Last edited by Scott; 03-06-2011 at 06:20 AM.. Reason: Please use code tags.
# 2  
Old 03-06-2011
Code:
awk '{ printf "%.0f\n", $1 - $2 }' list1

This User Gave Thanks to rdcwayx For This Post:
# 3  
Old 03-06-2011
awesome man!!thank you so much..it works perfect.Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. 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

2. Shell Programming and Scripting

Perl giving unexpected md5 hash values

I am trying to speed up creating a line by line hash file from a huge file using Perl. Here is my current (working but too slow) Bash code: (while read line; do hash=$(echo -n $line | md5sum); echo ${hash:0:32}; done)And here is my Perl code: perl -MDigest::MD5 -le 'foreach $line ( <STDIN> )... (3 Replies)
Discussion started by: Michael Stora
3 Replies

3. 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

4. Shell Programming and Scripting

awk subtraction and print output

FileA F97S 83 530 K569E 531 736 output shud be F16S K40E it is code sed 's///g' FileA |awk '{print $1-$2+2}' it will print 16 40 anything can come with this output?? (1 Reply)
Discussion started by: cdfd123
1 Replies

5. Shell Programming and Scripting

Turning off exponential notation in awk

I have various numbers that I'm printing out from a statistical summary script. I'd like it to stop using exponential format. Of course, I can use printf with 'd' and 'f' and various parameters to specify a format, but then it has other undesirable effects, like tacking on extra 0's or truncating... (0 Replies)
Discussion started by: treesloth
0 Replies

6. Shell Programming and Scripting

Converting Exponential values to decimals

Hi, I have a number of large (500Mb) txt files in the following format: 8.05475136E+05 9.69428147E+05 1 14 2968.00 3419.00 59.00 59 3.4028235E+38 2 w99-100 8.05464719E+05 9.69435064E+05 1 14 2968.03 3418.50 60.00 60 3.4028235E+38 2 w99-100 8.05454301E+05 ... (4 Replies)
Discussion started by: barrypitts
4 Replies

7. Shell Programming and Scripting

AWK subtraction in multiple columns

AWK subtraction in multiple columns Hi there, Can not get the following: input: 34523 934 9485 3847 394 3847 3456 9384 awk 'NR==1 {for (i = 1; i <= NF; i++) {n=$i; next}; {n-=$i} END {print n}' input output: 21188 first column only,... (2 Replies)
Discussion started by: awkward
2 Replies

8. Shell Programming and Scripting

awk subtraction

hi i have file 1 as follows: 6 7 8 9 10 i have file 2 as follows: 5 5 5 5 5 i want file 3 as follows: (4 Replies)
Discussion started by: npatwardhan
4 Replies

9. Shell Programming and Scripting

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,... (3 Replies)
Discussion started by: ssunda6
3 Replies

10. Shell Programming and Scripting

Converting exponential values

Hi. Is there a way to convert a value outputted as(for example): 4.14486e+06 into a regular format: 4144860 I suppose in plain english i want to move the decimal point 6 places to the right. please??? (2 Replies)
Discussion started by: rleebife
2 Replies
Login or Register to Ask a Question