AWK - Avoid exponential value | Unix Linux Forums | Shell Programming and Scripting

  Go Back    


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

AWK - Avoid exponential value

Shell Programming and Scripting


Tags
awk

Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 10-23-2012
Yoda's Avatar
Yoda Yoda is offline Forum Advisor  
Jedi Master
 
Join Date: Jan 2012
Last Activity: 2 September 2014, 9:11 PM EDT
Location: Galactic Empire
Posts: 3,362
Thanks: 230
Thanked 1,197 Times in 1,125 Posts
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

Sponsored Links
    #2  
Old 10-23-2012
rdrtx1 rdrtx1 is offline
Registered User
 
Join Date: Sep 2012
Last Activity: 15 July 2014, 11:14 AM EDT
Location: Houston, Texas, USA
Posts: 675
Thanks: 0
Thanked 203 Times in 195 Posts
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 06:40 PM.. Reason: avoid the line totally?
Sponsored Links
    #3  
Old 10-23-2012
Yoda's Avatar
Yoda Yoda is offline Forum Advisor  
Jedi Master
 
Join Date: Jan 2012
Last Activity: 2 September 2014, 9:11 PM EDT
Location: Galactic Empire
Posts: 3,362
Thanks: 230
Thanked 1,197 Times in 1,125 Posts
@rdrtx1 I'm sorry it is not working, still printing the exponential value. Can you recheck please?
    #4  
Old 10-23-2012
rdrtx1 rdrtx1 is offline
Registered User
 
Join Date: Sep 2012
Last Activity: 15 July 2014, 11:14 AM EDT
Location: Houston, Texas, USA
Posts: 675
Thanks: 0
Thanked 203 Times in 195 Posts
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 06:40 PM.. Reason: force int for $10
Sponsored Links
    #5  
Old 10-23-2012
Yoda's Avatar
Yoda Yoda is offline Forum Advisor  
Jedi Master
 
Join Date: Jan 2012
Last Activity: 2 September 2014, 9:11 PM EDT
Location: Galactic Empire
Posts: 3,362
Thanks: 230
Thanked 1,197 Times in 1,125 Posts
@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.
Sponsored Links
    #6  
Old 10-23-2012
rdrtx1 rdrtx1 is offline
Registered User
 
Join Date: Sep 2012
Last Activity: 15 July 2014, 11:14 AM EDT
Location: Houston, Texas, USA
Posts: 675
Thanks: 0
Thanked 203 Times in 195 Posts
See if update to last post works.
The Following User Says Thank You to rdrtx1 For This Useful Post:
Yoda (10-23-2012)
Sponsored Links
    #7  
Old 10-23-2012
Yoda's Avatar
Yoda Yoda is offline Forum Advisor  
Jedi Master
 
Join Date: Jan 2012
Last Activity: 2 September 2014, 9:11 PM EDT
Location: Galactic Empire
Posts: 3,362
Thanks: 230
Thanked 1,197 Times in 1,125 Posts
Work like a charm!! Thank you.
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
sum in exponential form jdsony Shell Programming and Scripting 7 01-26-2012 02:57 PM
Exponential issues Muthuraj K Shell Programming and Scripting 3 04-07-2011 09:01 AM
exponential format sandy1028 Shell Programming and Scripting 3 07-22-2010 12:51 PM
Turning off exponential notation in awk treesloth Shell Programming and Scripting 0 02-24-2010 08:44 PM
Convert exponential value to decimal Sangtha Shell Programming and Scripting 5 07-23-2009 12:04 AM



All times are GMT -4. The time now is 10:08 PM.