• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 304
  • Last Modified:

Unix shell script, How to do rounding of number ?

Below is my code. I want to check total number of lines and divided it by 2.

Suppose total no of lines =24 then I will divide by 2 = 12 .

But  when total no of lines =23 and then I will divide by 2 it gives 11 . I want 12 because actulay value is 11.5


ncnt=$((`wc -l < AMS_Total_Business_ID.txt` / 2))

Please help.
0
digs developer
Asked:
digs developer
  • 5
  • 3
1 Solution
 
ozoCommented:
ncnt=$(( ( `wc -l < AMS_Total_Business_ID.txt` + 1 ) / 2))
0
 
digs developerAuthor Commented:
But when I divide by 1000 is is not shown correct nmber like by 2.


ncnt=$(( ( `wc -l < AMS_Total_Business_ID.txt` + 1 ) / 1000))

division by value should be change on run time. It may be 500 ,900 or 1000

Please help.
0
 
ozoCommented:
ncnt=$(( ( `wc -l < AMS_Total_Business_ID.txt` + 500 ) / 1000))
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
digs developerAuthor Commented:
Thank you !
0
 
digs developerAuthor Commented:
I have one text file ABC_T_B_ID.txt which contains values in one column.
The values may be contain 1 or 1000 or 45000 and so on.

So my requirement is count the total line in a file and divided it by 1000 whatever the value comes that value should be ceil.

suppose
1. no of lines = 1000
   1000/1000 = 1
   
2. no of lines = 2000
   2000/1000 = 2

3. no of lines = 10
   10/1000 = 0.01   I need as 1  
   
4. no of lines = 411
   411/1000 = 0.411   I need as 1  

4. no of lines = 9898
   9898/1000 = 9.898   I need as 10    
   
4. no of lines = 9001
   9001/1000 = 9.001   I need as 10    
   
Below is my code.
Please help.  



ncnt=$(( ( `wc -l < ABC_T_B_ID.txt` + 500 ) / 1000))
0
 
digs developerAuthor Commented:
Please help
0
 
digs developerAuthor Commented:
Hello Experts,

Please need help
0
 
woolmilkporcCommented:
Seems you always want to round up:

ncnt=$(( ( `wc -l < ABC_T_B_ID.txt` + 999 ) / 1000))

More generally:

DIV=1000
ncnt=$(( ( `wc -l < ABC_T_B_ID.txt` + ($DIV-1) ) / $DIV))

Note Always rounding up will (for example) give 46 for 45001 lines divided by 1000. Is this desired?
0
 
ozoCommented:
ncnt=$(( ( `wc -l < ABC_T_B_ID.txt` + 999 ) / 1000))
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 5
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now