Sponsored Content
Full Discussion: Awk printf problem
Top Forums Shell Programming and Scripting Awk printf problem Post 302299205 by cazhot on Thursday 19th of March 2009 12:32:28 PM
Old 03-19-2009
Thanks for the answer.
The problem with this solution is that it does not round the float value, it truncates it.
 

10 More Discussions You Might Find Interesting

1. Programming

disturbing problem with PRINTF() !!

hello everybody, here is my problem: ________________________________________ #include <stdio.h> int main() { int i=10; printf("value is %i",i); return 0; } _________________________________________ when i compile and execute, nothing appears on screen!! but if i replace the printf... (2 Replies)
Discussion started by: brain_processin
2 Replies

2. UNIX for Advanced & Expert Users

awk printf problem

Hi Friends, Can anyone guide me how to compute sum of column4 from the below file x using awk command? when i do using awk I'm getting sum 7482350198352648.000000 which is not accurate. $ cat x 56,232,dfgjkhdfj,,56,anand 56,22,dfgjkhdfj,7482347823453123.97834 ,56,Khan 56,23,dfgjkhdfj, ... (6 Replies)
Discussion started by: krishna
6 Replies

3. Shell Programming and Scripting

perl: printf indentation problem

hi all, im having a problem with using perl printf. my requirement is to print a string (like ) at the right most end of the screen. i tried this perl script, but it fails with an error; #!/usr/bin/perl use strict; use warnings; my $scrW = 0; my $str = `stty size`; # get the... (5 Replies)
Discussion started by: wolwy_pete
5 Replies

4. Shell Programming and Scripting

printf problem

I have the following code: $ awk '{ printf "%-10s %s\n", $1, $2, $3, $4, $5, $5, $6 }' file i can only print the first 2 elements ($1,$2). How can i print all the elements to appear like this: aardvark 5555553 jhfjhfjkg efiigig ejkfjkej wjkdjk alpo-net 5553412 ... (2 Replies)
Discussion started by: DDoS
2 Replies

5. Shell Programming and Scripting

awk and printf

echo $bbsize 1.5 echo $fillpercent .95 echo $bbsize | awk '{printf "%.2f\n",$0*$fillpercent}' 2.25 echo $bbsize | awk '{printf "%.2f\n",$0*.95}' 1.42 1.42 is what I'm expecting... echo $blocksize 4096 echo $bbsize | awk '{printf "%.2f\n",$0*$blocksize}' 2.25 echo $bbsize |... (3 Replies)
Discussion started by: xgringo
3 Replies

6. Shell Programming and Scripting

IF and awk/printf

Hi Friends, Scripting newb here. So I'm trying to create a geektool script that uses awk and printf to output certain fields from top (namely command, cpu%, rsize, pid and time, in that order). After much trial and error, I've pretty much succeeded, with one exception. Any process whose name... (3 Replies)
Discussion started by: thom.mattson
3 Replies

7. Shell Programming and Scripting

Printf problem

I am having a major problem with printf, The more I pad it, the less I see :( The problem is in the first function, report Am I ruining output somewhere? I wont print out the names propely, it cuts them off or deletes them completely :( #!/bin/bash report() { printf "%-10s" STUD# ... (2 Replies)
Discussion started by: L0ckz0r
2 Replies

8. Shell Programming and Scripting

printf problem

In one of the scripts I am using pintf function as following printf "%s%s%s\n" "$f1" "$f2" "$f3" f3 variable contains a string of 10 characters. However it has value first 7 character and last 3 characters are empty. Example Aaaaaaa<3 spaces> bbbbbbb<3 spaces> ccccccc<3 spaces>... (4 Replies)
Discussion started by: varunrbs
4 Replies

9. Shell Programming and Scripting

awk with printf

Hi, I am using the following code to assign a count value to a variable. But I get nothing. Do you see anything wrong here. I am new to all this. $CTR=`remsh $m -l $MACHINES{$m} -n cat $output | grep -v sent | grep \"$input\" | sort -u | awk '{print $5}'`; Upto sort - u it's... (2 Replies)
Discussion started by: nurani
2 Replies

10. Shell Programming and Scripting

problem with printf in shell script

i have written small script as follows: name="hi hello" printf "%-20s" $name This gives me strange output. -20s format is applied on both word of string. i.e it displays both word hi and hello in space of 20 length. I want to display entire string "hi hello" in length of 20 space. plz... (2 Replies)
Discussion started by: admc123
2 Replies
ROUND(3)						   BSD Library Functions Manual 						  ROUND(3)

NAME
round, lround, llround -- round to integral value, regardless of rounding direction SYNOPSIS
#include <math.h> double round(double x); long double roundl(long double x); float roundf(float x); long int lround(double x); long int lroundl(long double x); long int lroundf(float x); long long int llround(double x); long long int llroundl(long double x); long long int llroundf(float x); DESCRIPTION
The round() functions return the integral value nearest to x rounding half-way cases away from zero, regardless of the current rounding direction. The lround() and llround() functions return the integral value nearest to x (rounding half-way cases away from zero, regardless of the cur- rent rounding direction) in the return formats specified. If the rounded value is outside the range of the return type, the numeric result is unspecified and the "invalid" floating-point exception is raised. A range error may occur if the magnitude of x is too large. SPECIAL VALUES
round(+-0) returns +-0. round(+-infinity) returns +-infinity. The round() functions may, but are not required to, raise the "inexact" floating-point exception for non-integer numeric arguments. The lround() and llround() functions need not raise the "inexact" floating-point exception for non-integer arguments that round to within the range of the return type. NOTE
The roundtol() function is deprecated. Please use the C99 function lround() instead. VECTOR OPERATIONS
If you need to apply the round() function to SIMD vectors or arrays, using the following functions provided by the Accelerate.framework may give significantly better performance: #include <Accelerate/Accelerate.h> vFloat vnintf(vFloat x); void vvnintf(float *y, const float *x, const int *n); void vvnint(double *y, const double *x, const int *n); SEE ALSO
ceil(3), floor(3), trunc(3), math(3) STANDARDS
The round() , lround() , and llround() functions conform to ISO/IEC 9899:2011. BSD
July 02, 2008 BSD
All times are GMT -4. The time now is 06:25 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy