|
|||||||
| Forums | Search Forums | Register | Forum Rules | Man Pages | Albums | FAQ | Members | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
||||
|
||||
|
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 } ' infileCode:
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
|
|||
|
|||
|
try: Code:
awk ' BEGIN { OFS=FS="|" } $10 !~ /[+]/ { if(NF>4) $10=int(((3.77*$11)/100 + $11)); print } ' infileLast edited by rdrtx1; 10-23-2012 at 06:40 PM.. Reason: avoid the line totally? |
| Sponsored Links | ||
|
|
#3
|
||||
|
||||
|
@rdrtx1 I'm sorry it is not working, still printing the exponential value. Can you recheck please?
|
|
#4
|
|||
|
|||
|
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 } ' infileoutput: 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
|
||||
|
||||
|
@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 | |
|
|
#7
|
||||
|
||||
|
Work like a charm!! Thank you.
|
| Sponsored Links | ||
|
![]() |
| Tags |
| awk |
| Thread Tools | Search this Thread |
| 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 |
|
|