Sponsored Content
Full Discussion: AWK rounding up numbers
Top Forums Shell Programming and Scripting AWK rounding up numbers Post 302444682 by Franklin52 on Thursday 12th of August 2010 12:55:37 PM
Old 08-12-2010
Quote:
Originally Posted by keenboy100
Thanks.

My file has 15 columns and quite a few lines. I would like to round up the numbers of column 14 only. The other columns don't contain numbers.

The file is like this:

Code:
,fred,a,b,c,e,f,g,h,i,j,k,l,m,4.7,z,
,henry,a,b,c,e,f,g,h,i,j,k,l,m,1.4,z,
,bob,a,b,c,e,f,g,h,i,j,k,l,m,3.2,z,

The output should be:

Code:
,fred,a,b,c,e,f,g,h,i,j,k,l,m,5,z,
,henry,a,b,c,e,f,g,h,i,j,k,l,m,2,z,
,bob,a,b,c,e,f,g,h,i,j,k,l,m,4,z,

Thanks,
Try this:
Code:
awk -F, '{$15=$15==int($15)?int($15):int($15)+1}1' OFS=","

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

match numbers (awk)

i would like to enter (user input) a bunch of numbers seperated by space: 10 15 20 25 and use awk to print out any lines in a file that have matching numbers so output is: 22 44 66 55 (10) 77 (20) (numbers 10 and 20 matched for example) is this possible in awk . im using gawk for... (5 Replies)
Discussion started by: tanku
5 Replies

2. Shell Programming and Scripting

Rounding off using BC.

Hello again. I'm trying to use BC to calculate some numbers in a shell script. I want to have the numbers rounded off to 1 decimal place. for example: initsize=1566720 zipsize=4733 I'm trying to get the ratio between them. the equation is: (($initsize-$zipsize)/$initsize)*100 so... (3 Replies)
Discussion started by: noodlesoup
3 Replies

3. Shell Programming and Scripting

to count their numbers using awk

suppose u have a file AAG AAG GYG HYH GTG AAG AAG HYH GYG HUH JUJ JUJ AAG so output shud have AAG = 5 GYG=2 HYH=2 HUH=1JUJ=2 (3 Replies)
Discussion started by: cdfd123
3 Replies

4. UNIX for Dummies Questions & Answers

Annoying rounding issue in awk

Hello I am getting this very annoying issue in awk: awk '{a=12825;b=a*1.25; print b}' test 16031.2 Thing is the multiplication result is wrong... Result should be 16031.25. I think the issue only happens on bigger numbers. What can I do to get passed this? Thanks by advance (3 Replies)
Discussion started by: Indalecio
3 Replies

5. Shell Programming and Scripting

Rounding issue with awk

Hi Friends, I am trying to round following number. 0.07435000 echo "0.07435000"|awk '{printf "%s\n",$1*100}'|awk '{printf "%.2f\n",$1}' It returns: 7.435 It should return: 7.44 Any suggestion please? Thanks, Prashant (2 Replies)
Discussion started by: ppat7046
2 Replies

6. Shell Programming and Scripting

awk, floating point and rounding

I had a person bring an interesting problem to me that appears to involve some sort of rounding inside awk. I've verified this with awk and nawk on Solaris as well as with gawk 3.1.5 on a Linux box. The original code fragment he brought me was thus: for (index=0; index < 1; index=index+.1) ... (4 Replies)
Discussion started by: mmyer2
4 Replies

7. Shell Programming and Scripting

AWK series of numbers

Hi, I have a dataset say 1 2 3 4 5 5 6 7 6 7 8 9 I was wondering if there is a way to add another column with the following style... 1 2 3 4 xyz_1 5 5 6 7 xyz_2 6 7 8 9 xyz_3 It would be greatly appreciated if I can have an option of specifying what to write instead of xyz,... (8 Replies)
Discussion started by: jacobs.smith
8 Replies

8. Shell Programming and Scripting

awk calculation automatically rounding off the output

I have some calculation in my script which is similar to the below example . I find that sometimes when using large decimal digits, the output gets automatically rounded off and it is affecting the program. I am not able to understand what is happening here.. awk '{ a=6.32498922 a1=6.324... (5 Replies)
Discussion started by: wanderingmind16
5 Replies

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

10. 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
IGAWK(1)							 Utility Commands							  IGAWK(1)

NAME
igawk - gawk with include files SYNOPSIS
igawk [ all gawk options ] -f program-file [ -- ] file ... igawk [ all gawk options ] [ -- ] program-text file ... DESCRIPTION
Igawk is a simple shell script that adds the ability to have ``include files'' to gawk(1). AWK programs for igawk are the same as for gawk, except that, in addition, you may have lines like @include getopt.awk in your program to include the file getopt.awk from either the current directory or one of the other directories in the search path. OPTIONS
See gawk(1) for a full description of the AWK language and the options that gawk supports. EXAMPLES
cat << EOF > test.awk @include getopt.awk BEGIN { while (getopt(ARGC, ARGV, "am:q") != -1) ... } EOF igawk -f test.awk SEE ALSO
gawk(1) Effective AWK Programming, Edition 1.0, published by the Free Software Foundation, 1995. AUTHOR
Arnold Robbins (arnold@skeeve.com). Free Software Foundation Nov 3 1999 IGAWK(1)
All times are GMT -4. The time now is 09:15 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy