awk calculation problem


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting awk calculation problem
# 1  
Old 11-06-2008
awk calculation problem

I have a list of coordinate data, sampled below.

54555209 784672723

I want it as:

545552.09 7846727.23

Below is my script:

BEGIN {FS= " "; OFS= ","} {print $1*.01,$2*.01}

This is my outcome:
5.5e7 7.8e8

How do I tell awk that I want to keep all the digits instead of outputting scientific notation.
# 2  
Old 11-06-2008
Try this for 2 digits
Code:
awk '{v=100;printf "%.2f,%.2f\n",$1/v, $2/v}' file

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk calculation with zero as N/A

In the below awk, I am trying to calculate percent for a given id. It is very close the problem is when the # being used in the calculation is zero. I am not sure how to code this condition into the awk as it happens frequently. The portion in italics was an attempt but that lead to an error. Thank... (13 Replies)
Discussion started by: cmccabe
13 Replies

2. Shell Programming and Scripting

awk split and awk calculation in the same command

I am trying to run the awk below. My question is when I split the input, then run anotherawk to perform a calculation using that splitas the input there are no issues. When I try to combine them the output is not correct, is the split not working or did I do it wrong? Thank you :). input ... (8 Replies)
Discussion started by: cmccabe
8 Replies

3. Shell Programming and Scripting

Decimal number calculation problem

I have a below snippet of code from my perl script and its causing a problem when the output of $lTAX is 0 (zero) its getting displayed as -0.00. I want output to be 0 not -0.00. Any help would be appreciated. #!/usr/bin/perl my $lTotA = 50.94; my $lVatA = 8.49; my $lAllocD; my $lAdjNr =... (4 Replies)
Discussion started by: Devesh5683
4 Replies

4. Shell Programming and Scripting

Awk or If/statement Calculation Problem

#!/bin/sh CURRENTSTATE=2 CSVCSTATE=2 LASTSTATECHANGE=8 CSVCSTATEAGE=5 if (($CURRENTSTATE==$CSVCSTATE))&&(($LASTSTATECHANGE>=$CSVCSTATEAGE)) echo GREAT fi returns: ./aff: line 12: syntax error near unexpected token `fi' ./aff: line 12: `fi' what am i doing wrong here? (6 Replies)
Discussion started by: SkySmart
6 Replies

5. Programming

arithmetic calculation using awk

hi there again, i need to do a simple division with my data with a number of rows. i think i wanted to have a simple output like this one: col1 col2 col3 val1 val2 val1/val2 valn valm valn/valm any suggestion is very much appreciated. thanks much. (2 Replies)
Discussion started by: ida1215
2 Replies

6. Shell Programming and Scripting

Problem in echo value after some calculation

val=21 total=3250 echo "`echo "scale=2; $val*100/$total" | bc`" Output: .64 How do i show the output become "0.64" instead of ".64" ?? Someone can help? (1 Reply)
Discussion started by: alvin0618
1 Replies

7. Shell Programming and Scripting

Ksh Solaris Time calculation problem..Please help

I've gone through bunch of threads on time calculations but none of them helps on my problem I've to get the time difference in HHMM format from following inputs Input 1 : 01/08/2010 01:30 01/08/2010 03:20 Input 2 : 01/06/2010 22:00 01/07/2010 16:00 First input is easy but... (8 Replies)
Discussion started by: prash184u
8 Replies

8. Shell Programming and Scripting

Problem with float calculation and awk

Hi All, can some body help me to script the below logic. Basically am facing problem with float calculation. Also i need this to be done inside a single awk. I tried lot of tuning but still nothing is getting displayed, nor any errors param=50 value=19.23 for(i=0;i<4;i++) {... (2 Replies)
Discussion started by: jisha
2 Replies

9. UNIX for Advanced & Expert Users

Reattemps Calculation using awk

Dear All How are you I have files which look like this : 20080406_12:43:55.779 ISC Sprint- 39 21624032999 218925866728 20080406_12:44:07.811 ISC Sprint- 20 21620241815 218927736810 20080406_12:44:00.485 ISC Sprint- 50 21621910404 218913568053... (0 Replies)
Discussion started by: zanetti321
0 Replies

10. Shell Programming and Scripting

awk calculation

Hallo all, I have a script which creates an output ... see below: root@a7germ:/tmp/pax > cat 20061117.txt 523.047 521.273 521.034 517.367 516.553 517.793 513.114 513.940 I would like to use awk to calculate the (a)total sum of the numbers (b) The average of the numbers. Please... (4 Replies)
Discussion started by: kekanap
4 Replies
Login or Register to Ask a Question