Unix/Linux Go Back    


Shell Programming and Scripting BSD, Linux, and UNIX shell scripting — Post awk, bash, csh, ksh, perl, php, python, sed, sh, shell scripts, and other shell scripting languages questions here.

AWK - Avoid exponential value

Shell Programming and Scripting


Tags
awk

Closed    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 10-23-2012
Yoda's Unix or Linux Image
Yoda Yoda is offline Forum Advisor  
Jedi Master
 
Join Date: Jan 2012
Last Activity: 5 December 2016, 4:51 PM EST
Location: Galactic Empire
Posts: 3,529
Thanks: 248
Thanked 1,281 Times in 1,203 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 Unix and Linux 10-23-2012
rdrtx1 rdrtx1 is offline
Registered User
 
Join Date: Sep 2012
Last Activity: 30 November 2016, 11:31 AM EST
Location: Houston, Texas, USA
Posts: 873
Thanks: 0
Thanked 299 Times in 286 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 07:40 PM.. Reason: avoid the line totally?
Sponsored Links
    #3  
Old Unix and Linux 10-23-2012
Yoda's Unix or Linux Image
Yoda Yoda is offline Forum Advisor  
Jedi Master
 
Join Date: Jan 2012
Last Activity: 5 December 2016, 4:51 PM EST
Location: Galactic Empire
Posts: 3,529
Thanks: 248
Thanked 1,281 Times in 1,203 Posts
@rdrtx1 I'm sorry it is not working, still printing the exponential value. Can you recheck please?
    #4  
Old Unix and Linux 10-23-2012
rdrtx1 rdrtx1 is offline
Registered User
 
Join Date: Sep 2012
Last Activity: 30 November 2016, 11:31 AM EST
Location: Houston, Texas, USA
Posts: 873
Thanks: 0
Thanked 299 Times in 286 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 07:40 PM.. Reason: force int for $10
Sponsored Links
    #5  
Old Unix and Linux 10-23-2012
Yoda's Unix or Linux Image
Yoda Yoda is offline Forum Advisor  
Jedi Master
 
Join Date: Jan 2012
Last Activity: 5 December 2016, 4:51 PM EST
Location: Galactic Empire
Posts: 3,529
Thanks: 248
Thanked 1,281 Times in 1,203 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 Unix and Linux 10-23-2012
rdrtx1 rdrtx1 is offline
Registered User
 
Join Date: Sep 2012
Last Activity: 30 November 2016, 11:31 AM EST
Location: Houston, Texas, USA
Posts: 873
Thanks: 0
Thanked 299 Times in 286 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 Unix and Linux 10-23-2012
Yoda's Unix or Linux Image
Yoda Yoda is offline Forum Advisor  
Jedi Master
 
Join Date: Jan 2012
Last Activity: 5 December 2016, 4:51 PM EST
Location: Galactic Empire
Posts: 3,529
Thanks: 248
Thanked 1,281 Times in 1,203 Posts
Work like a charm!! Thank you.
Sponsored Links
Closed

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux 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 03:57 PM
Exponential issues Muthuraj K Shell Programming and Scripting 3 04-07-2011 10:01 AM
exponential format sandy1028 Shell Programming and Scripting 3 07-22-2010 01:51 PM
Turning off exponential notation in awk treesloth Shell Programming and Scripting 0 02-24-2010 09:44 PM
Convert exponential value to decimal Sangtha Shell Programming and Scripting 5 07-23-2009 01:04 AM



All times are GMT -4. The time now is 01:40 AM.