Float number format problem -Awk


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Float number format problem -Awk
# 1  
Old 08-01-2010
Float number format problem -Awk

Here is the script I'm using

Code:
awk '{print $1,"\t",(($2+$3)/2)-x,"\t",(($2+$3)/2)+x,"\t",$4,"\t",$5}' x=500 $1

I just want to make float numbers (red) like normal numbers (green)
output
Code:
cX     1.65107e+08     1.65108e+08     13      64.2
cX     165112764       165113764       27      96.7
cX     165142764       165143764       14      53.73
cX     1.65325e+08     1.65326e+08     180     55.96

Help would be appreciated
Thanx
# 2  
Old 08-02-2010
Use printf:

e.g.
Code:
$ awk -F ":" '{sum+=$NF} END {print sum}' data.txt
1.27084e+10

$ awk -F ":" '{sum+=$NF} END { printf ("%0.0f\n", sum)} ' data.txt
12708429091

$ awk -F ":" '{sum+=$NF} END { printf ("%d\n", sum)} ' data.txt
12708429091

# 3  
Old 08-02-2010
Not working

Code:
awk -F '{printf ("%0.0f\n",$1,"\t",(($2+$3)/2)-500,"\t",(($2+$3)/2)+500,"\t",$4,"\t",$5)}' x=500 $1

# 4  
Old 08-02-2010
Hi, could you please provide few of sample lines from your input file.
# 5  
Old 08-02-2010
Here is the sample

Code:
cX    165112562       165113966       27      96.7
cX    165142877       165143651       14      53.73
cX    165323227       165327550       180     55.96

# 6  
Old 08-02-2010
Code:
$ awk '{print $1,"\t",(($2+$3)/2)-x,"\t",(($2+$3)/2)+x,"\t",$4,"\t",$5}' x=500 file.txt 
cX 	 165112764 	 165113764 	 27 	 96.7
cX 	 165142764 	 165143764 	 14 	 53.73
cX 	 1.65325e+08 	 1.65326e+08 	 180 	 55.96

$ awk '{printf ("%s\t%0.0f\t%0.0f\t%0.0f\t%0.2f\n", $1, (($2+$3)/2)-500, (($2+$3)/2)+500, $4, $5)}' file.txt 

cX	165112764	165113764	27	96.70
cX	165142764	165143764	14	53.73
cX	165324888	165325888	180	55.96

# 7  
Old 08-02-2010
hi

working fine. but so many symbols ha!

Thanx
Ruby
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

Python : Problem with " TypeError: float() argument must be a string or a number "

Hello ! I'm creating a CGI which allow to display graph from some data. The datas looks like : 2020-01-13-00-00,384.00,350.00 2020-01-13-06-00,384.00,350.00 2020-01-13-12-00,384.00,350.00 2020-01-13-18-00,384.00,350.00 2020-01-14-00-00,384.00,350.00... (1 Reply)
Discussion started by: Tim2424
1 Replies

2. Shell Programming and Scripting

Sed/awk command to convert number occurances into date format and club a set of lines

Hi, I have been stuck in this requirement where my file contains the below format. 20150812170500846959990854-25383-8.0.0 "ABC Report" hp96880 "4952" 20150812170501846959990854-25383-8.0.0 End of run 20150812060132846959990854-20495-8.0.0 "XYZ Report" vg76452 "1006962188"... (6 Replies)
Discussion started by: Chinmaya Kabi
6 Replies

3. Shell Programming and Scripting

[awk] rounding a float number?

Heyas Trying to calculate the total size of a file by reading its bitrate. Code snippet: fs_expected() { # # Returns the expected filesize in bytes # pr_str() { ff=$(cat $TMP.info) d="${ff#*bitrate: }" echo "${d%%,*}" | $AWK '{print $1}' | head -n 1 } t_BYTERATE=$((... (9 Replies)
Discussion started by: sea
9 Replies

4. Shell Programming and Scripting

printf (awk,perl,shell) float rounding issue

Hi guys, could someone throw some light on the following behaviour of printf (I'll start with info about the system and the tool/shell/interpreter versions)?: $ uname -a Linux linux-86if.site 3.1.0-1.2-desktop #1 SMP PREEMPT Thu Nov 3 14:45:45 UTC 2011 (187dde0) x86_64 x86_64 x86_64... (9 Replies)
Discussion started by: elixir_sinari
9 Replies

5. Shell Programming and Scripting

awk:How to format a number?

Hello, I need to format a number..like 12900 should be printed as 12,900 and 1209 as 1,209 and so on. (Just like we do in excel). Can this be done in awk. any printf options we have?Please suggest me. Thanks! (8 Replies)
Discussion started by: vijay_0209
8 Replies

6. Shell Programming and Scripting

How to format the output using float in awk{printf}

Hi I'm using awk to manipulate the data in the 6th field of the file xxx_yyy.hrv. The sample data that is available in this field is given below 220731.7100000000000000 When i tried using this command cat xxx_yyy.hrv | awk '{printf("%23.16f\n",$6*-1)}' I get the output as... (4 Replies)
Discussion started by: angelarosh
4 Replies

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

8. Programming

math.h: float ceilf(float x)

Good morning, I'm testing the use of ceilf: /*Filename: str.c*/ #include <stdio.h> #include <math.h> int main (void) { float ceilf(float x); int dev=3, result=0; float tmp = 3.444f; printf("Result: %f\n",ceilf(tmp)); return 0; } (1 Reply)
Discussion started by: jonas.gabriel
1 Replies

9. Shell Programming and Scripting

comparing float with int / number

Hi all, I'm looking to modify a script to check disk space usage. Here is the code at the moment: # # The control file, MONITOR_DISK_SPACE, must be in the format ... Drive:;threshold_percentage # eg. # C:;95 # D:;98 # E:;90 # # For each line in the control file (MONITOR_DISK_SPACE)... (2 Replies)
Discussion started by: lelliott
2 Replies

10. UNIX for Dummies Questions & Answers

Integer/Float Script Problem

Hi, I have a script which takes a value from a file and performs calculations on it. Trouble is that this value is a float not an integer and it errors at the decimal point! eg. 94.62 I would like to be able to detect the length of the float (in this above case, 5 characters), and simply do a... (2 Replies)
Discussion started by: danhodges99
2 Replies
Login or Register to Ask a Question