AWK - Avoid exponential value


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting AWK - Avoid exponential value
# 1  
Old 10-23-2012
AWK - Avoid exponential value

I'm using the following command, but how can I avoid printing exponential value (highlighted):-

Code:
awk ' BEGIN  { OFS=FS="|" } { if(NF>4) $10=int(((3.77*$11)/100 + $11)); } { print } ' infile

Code:
CR|20121022|105|GSM|N|SAN|00122|SAN|75082|6.03929e+06|5819880|5794769|25111
CR|20121022|105|GSM|N|SAN|00122|SAN|75118|2613|2519|2514|5
CR|20121022|105|GSM|N|SAN|00122|SAN|75119|157324|151609|151455|154
CR|20121022|105|GSM|N|SAN|30204|SAN|75082|95919|92435|91479|956
CR|20121022|105|GSM|N|SAN|30204|SAN|75118|894|862|835|27
CR|20121022|105|GSM|N|SAN|30204|SAN|75119|5132|4946|4901|45
CR|20121022|105|GSM|N|SAN|30214|SAN|75082|20167|19435|19434|1
CR|20121022|105|GSM|N|SAN|30214|SAN|75118|639|616|616|0
CR|20121022|105|GSM|N|SAN|30214|SAN|75119|4860|4684|4658|26
CR|20121022|105|GSM|N|SAN|30282|SAN|75082|17462|16828|16821|7
CR|20121022|105|GSM|N|SAN|30282|SAN|75118|1607|1549|1548|1
CR|20121022|105|GSM|N|SAN|30282|SAN|75119|87245|84076|83910|166

# 2  
Old 10-23-2012
try:
Code:
awk ' BEGIN  { OFS=FS="|" } $10 !~ /[+]/ { if(NF>4) $10=int(((3.77*$11)/100 + $11)); print } ' infile


Last edited by rdrtx1; 10-23-2012 at 07:40 PM.. Reason: avoid the line totally?
# 3  
Old 10-23-2012
@rdrtx1 I'm sorry it is not working, still printing the exponential value. Can you recheck please?
# 4  
Old 10-23-2012
infile:
Code:
CR|20121022|105|GSM|N|SAN|00122|SAN|75082|6.03929e+06|5819880|5794769|25111
CR|20121022|105|GSM|N|SAN|00122|SAN|75118|2613|2519|2514|5
CR|20121022|105|GSM|N|SAN|00122|SAN|75119|157324|151609|151455|154
CR|20121022|105|GSM|N|SAN|30204|SAN|75082|95919|92435|91479|956
CR|20121022|105|GSM|N|SAN|30204|SAN|75118|894|862|835|27
CR|20121022|105|GSM|N|SAN|30204|SAN|75119|5132|4946|4901|45
CR|20121022|105|GSM|N|SAN|30214|SAN|75082|20167|19435|19434|1
CR|20121022|105|GSM|N|SAN|30214|SAN|75118|639|616|616|0
CR|20121022|105|GSM|N|SAN|30214|SAN|75119|4860|4684|4658|26
CR|20121022|105|GSM|N|SAN|30282|SAN|75082|17462|16828|16821|7
CR|20121022|105|GSM|N|SAN|30282|SAN|75118|1607|1549|1548|1
CR|20121022|105|GSM|N|SAN|30282|SAN|75119|87245|84076|83910|166

using:
Code:
awk ' BEGIN  { OFS=FS="|" } $10 !~ /x/ { if(NF>4) $10=sprintf("%d",int(((3.77*$11)/100 + $11))); print } ' infile

output:
Code:
CR|20121022|105|GSM|N|SAN|00122|SAN|75082|6039289|5819880|5794769|25111
CR|20121022|105|GSM|N|SAN|00122|SAN|75118|2613|2519|2514|5
CR|20121022|105|GSM|N|SAN|00122|SAN|75119|157324|151609|151455|154
CR|20121022|105|GSM|N|SAN|30204|SAN|75082|95919|92435|91479|956
CR|20121022|105|GSM|N|SAN|30204|SAN|75118|894|862|835|27
CR|20121022|105|GSM|N|SAN|30204|SAN|75119|5132|4946|4901|45
CR|20121022|105|GSM|N|SAN|30214|SAN|75082|20167|19435|19434|1
CR|20121022|105|GSM|N|SAN|30214|SAN|75118|639|616|616|0
CR|20121022|105|GSM|N|SAN|30214|SAN|75119|4860|4684|4658|26
CR|20121022|105|GSM|N|SAN|30282|SAN|75082|17462|16828|16821|7
CR|20121022|105|GSM|N|SAN|30282|SAN|75118|1607|1549|1548|1
CR|20121022|105|GSM|N|SAN|30282|SAN|75119|87245|84076|83910|166


Last edited by rdrtx1; 10-23-2012 at 07:40 PM.. Reason: force int for $10
# 5  
Old 10-23-2012
@rdrtx1 I'm sorry if I confused you. When I said I don't want to print exponential value, I mean exponential value has to be printed as normal. So instead of 6.03929e+06 it should print 6039289. I see your awk script is not printing that line instead! Your help is much appreciated.
# 6  
Old 10-23-2012
See if update to last post works.
This User Gave Thanks to rdrtx1 For This Post:
# 7  
Old 10-23-2012
Work like a charm!! Thank you.
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

How to avoid column with a specific name using awk

how can avoid column names that start with Nx_*? file1 name Nx_8977 Nx_988 NN a1 2 0 8 b1 2 0 8 ouput name NN a1 8 b1 8 (5 Replies)
Discussion started by: quincyjones
5 Replies

3. Shell Programming and Scripting

Exponential issues

I have the below awk command to search a row and find the line number. It returns the value in exponential. I understand we can use the print "%.0f\n" to convert the exponential. I wanted to have this in my awk command. Can anyone advise bnd=`awk '/^GS/{p=NR}$0~"^ABC.*\\*"k{f=1}/^GE/&&f{print... (3 Replies)
Discussion started by: Muthuraj K
3 Replies

4. Shell Programming and Scripting

The awk subtraction giving exponential values.Please help resolve it

Hi friends, I have a file list1 which has these 2 columns like 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: awk '{ print $1 - $2 }' list1 >... (2 Replies)
Discussion started by: kunwar
2 Replies

5. Shell Programming and Scripting

exponential format

awk -F"\t" -vv1=$name 'BEGIN{OFS="\t"} {gsub ("http://www."v1".com","",$6);print $1"\t-\t-","",$6,$7,$9,$2,$14,$15"\t""Apache=-\t-",$8*1000000"\t-\t-\t-\tdeflate=-\trmt=-"}' file.txt > a.txt file.txt 144.130.7.153 www.chi.com - 18/Jul/2010:00:00:00 +0000 GET... (3 Replies)
Discussion started by: sandy1028
3 Replies

6. Shell Programming and Scripting

Joining 3 AWK scripts to avoid use "temp" files

Hi everyone, Looking for a suggestion to improve the below script in which I´ve been working. The thing is I have 3 separated AWK scripts that I need to apply over the inputfile, and for scripts (2) and (3) I have to use a "temp" file as their inputfile (inputfile_temp and inputfile_temp1... (2 Replies)
Discussion started by: cgkmal
2 Replies

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

8. Shell Programming and Scripting

awk command to avoid loops

Hi... I need a help in using the awk command or any other solution to avoid the usage of loops. My question is : I have a input like this : field1|field2|field3|field4|field5|field6|field7|field8|field9 ex : 4000|testing|scenario|14450|500|320|450|200|100 where the... (2 Replies)
Discussion started by: vijayarajvp
2 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

AWK: How to avoid System

How can we avoid the use of system command inside awk program? Is there any alternative way in awk programming for removing files, sorting files and to find the differences between two file without using a system command? Eg: system("rm tempfil006"); How to avoid the use of system in above... (0 Replies)
Discussion started by: sandeep_hi
0 Replies
Login or Register to Ask a Question