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.

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
} 

Without seeing what is in the file named by $1, the output you're trying get, and how that is different from the output you are getting, we have no way of guessing what is wrong with your code.

Hi Don,
Following are some of the lines of the file passed as $1. Please look into this and suggest

5000044903|1|9152|295052|MB|20131201000001|10487450|N||0|10335910|151540|C28053OB|533|SSCHHA01S201312010005000000.PDSN|0
41619703|45|9152|093905|MB|20131201000346|9912683|N||0|8998792|913891|C2205Ohz|533|SSCHHA01S201312010005000000.PDSN|0
41619703|45|9152|093905|MB|20131201000346|569377|N||0|550139|19238|C2205Ohz|534|SSCHHA01S201312010005000000.PDSN|0
41619703|45|9152|093905|MB|20131201000346|479|N||0|0|479|C2205Ohz|336|SSCHHA01S201312010005000000.PDSN|0
41619703|45|9152|093905|MB|20131201000346|1107|N||0|909|198|C2205Ohz|335|SSCHHA01S201312010005000000.PDSN|0
41619703|45|9152|093905|MB|20131201000346|2161|N||0|1378|783|C2205Ohz|334|SSCHHA01S201312010005000000.PDSN|0
5000052620|1|9152|133596|MB|20131201000445|7688246|N||0|7308890|379356|C21055UW|533|SSCHHA01S201312010005000000.PDSN|0
5000052620|1|9152|133596|MB|20131201000445|2798798|N||0|2528150|270648|C21055UW|534|SSCHHA01S201312010005000000.PDSN|0
5000052620|1|9152|133596|MB|20131201000445|0|N||0|0|0|C21055UW|334|SSCHHA01S201312010005000000.PDSN|0
41619703|45|9152|093905|MB|20131201000846|5270324|N||0|4870952|399372|C2205OiX|533|SSCHHA01S201312010010000001.PDSN|0

I repeat: "Without seeing what is in the file named by $1, the output you're trying get, and how that is different from the output you are getting, we have no way of guessing what is wrong with your code."

Hi Siramitsharma,

It would be good if you can provide us desire output (based on input which you have provided in earlier post).

Thanks
Pravin

Saw my code again...& found the bug :slight_smile: