Sponsored Content
Top Forums Shell Programming and Scripting Ceil not working as function in awk statement Post 302877498 by siramitsharma on Sunday 1st of December 2013 11:06:37 PM
Old 12-02-2013
Ceil not working as function in awk statement

Hi,
I have the following code in which i am trying to find ceil of 10th & 11th fields. For finding ceil i have a function in the awk statement. When i test it for some values say on command line it gives correct response(say $10=0 & $11=750). But when the same value occurs in a file having more 3 millions records(it is just an example & behaviour is abrupt for some cases), the value gets impacted. Can you please suggest in case some modifications are required.

Code:
function pdsnrater()
 {
  awk -F"|" ' 
  function ceil(val) { return (val == int(val)) ? val : int(val)+1}
  { 
   if ($5 == "MB")
   printf("%s,%s,%s,%s,%s,%d,%s,%s,%s,%s,%s,%s,%d,%s,%s,%s\n",$1,$2,$3,$4,$6,ceil(($10+$11)/1024/1024),$8,$9,$10,$11,$12,$13,$14,$15,$16,$5) 
   else
   printf("%s,%s,%s,%s,%s,%d,%s,%s,%s,%s,%s,%s,%d,%s,%s,%s\n", $1,$2,$3,$4,$6,ceil(($10+$11)/1024/10),$8,$9,$10,$11,$12,$13,$14,$15,$16,$5)
  } ' FS="|" OFS="|" $1 > $1.tmp
  mv $1.tmp $1
}

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

If statement not working

I understand this question probably poses some child like stupidity, but I can't get this if statement to work for love or money. #!/bin/ksh echo "Input either 1 or 2" read Num if ; then echo "Message 1" if ; then echo "Message 2" else echo "false" fi $ ksh decisions Input either 1... (6 Replies)
Discussion started by: Hazmeister
6 Replies

2. Shell Programming and Scripting

Using Subroutine / Function in case statement

I have issue running functions under case statement #!/bin/bash single() { Commands } multiple() { Commands } until ; do echo -e " \t \t M A I N - M E N U Perforce delete script \n" (1 Reply)
Discussion started by: sriram003
1 Replies

3. Shell Programming and Scripting

read statement not working in a function

Pls this is emergency.I have written a script which is taking input from another script. and the contents of my second script are acting as functions to my main script.Now the problem is that in one of the functions i want the script ececution to stop and start when user enters any character r... (2 Replies)
Discussion started by: sumitdua
2 Replies

4. Shell Programming and Scripting

If statement is not working.

Hi. With the help of this group I have created a shell script to find the factorial of a number. OK. Then I got wild.;) I tried to put in a check to make sure the entry is a number. read num If )) then echo "This is not a valid number. Try again." fi while (( $var <= $num)) more... (5 Replies)
Discussion started by: Ccccc
5 Replies

5. Shell Programming and Scripting

Calling function in awk statement.

Hi All, I have an awk statement and a function defined in a script. I am trying to call the function from inside awk statement, i.e. awk ' myFunk () ;' filename But when I define myFunk() before awk, then I receive this error: s2.sh: line 48: syntax error: unexpected end of file and... (5 Replies)
Discussion started by: morningSunshine
5 Replies

6. Shell Programming and Scripting

Embed function in if statement

Hey everyone, I am just trying to figure out how to embed a function in an if statement. I have the following test script so far: PRIMARY=192.168.1.2 SECONDARY=192.168.1.1 function checkAlive { ping -c 1 -q $1 } if then echo "equaled 0" fi This... (1 Reply)
Discussion started by: msarro
1 Replies

7. Shell Programming and Scripting

Running a function from a case statement

Hi, I have the below script that should take the command line option and run the desired script on another server. Only it doesn't seem to run the function, infact it just returns back to the command line. case $1 in 1) msgbacklog() ;; 2) jobstatus() ;; ... (10 Replies)
Discussion started by: chris01010
10 Replies

8. Programming

A single statement without main function in c

A sample.c file is written with only one single statement. main; Segmentation fault occurred when executed that file. Any statement other than main; is written, for example unix; then it won't compile. why is this behaviour ! (2 Replies)
Discussion started by: techmonk
2 Replies

9. Shell Programming and Scripting

Convert Update statement into Insert statement in UNIX using awk, sed....

Hi folks, I have a scenario to convert the update statements into insert statements using shell script (awk, sed...) or in database using regex. I have a bunch of update statements with all columns in a file which I need to convert into insert statements. UPDATE TABLE_A SET COL1=1 WHERE... (0 Replies)
Discussion started by: dev123
0 Replies

10. Shell Programming and Scripting

awk call in bash function called with arugments not working, something lost in translation?

Hello, I have this awk code in a bash script to perform a find and replace task. This finds one unique line in a file and substitutes the found line with a replacement. #! /bin/bash # value determined elsewhere total_outputs_p1=100 # file being modified... (5 Replies)
Discussion started by: LMHmedchem
5 Replies
ceil(3M)						  Mathematical Library Functions						  ceil(3M)

NAME
ceil, ceilf, ceill - ceiling value function SYNOPSIS
c99 [ flag... ] file... -lm [ library... ] #include <math.h> double ceil(double x); float ceilf(float x); long double ceill(long double x); DESCRIPTION
These functions compute the smallest integral value not less than x. RETURN VALUES
Upon successful completion, the ceil(), ceilf(), and ceill() functions return the smallest integral value not less than x, expressed as a type double, float, or long double, respectively. If x is NaN, a NaN is returned. If x is +-0 or +-Inf, x is returned. USAGE
The integral value returned by these functions need not be expressible as an int or long int. The return value should be tested before assigning it to an integer type to avoid the undefined results of an integer overflow. ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Interface Stability |Standard | +-----------------------------+-----------------------------+ |MT-Level |MT-Safe | +-----------------------------+-----------------------------+ SEE ALSO
feclearexcept(3M), fetestexcept(3M), floor(3M), isnan(3M), math.h(3HEAD), attributes(5), standards(5) SunOS 5.11 12 Jul 2006 ceil(3M)
All times are GMT -4. The time now is 06:40 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy