The idea is: there is such a file:

Interworking - unspecified,127,1,2016/04/06 17:40,EMPTY,RNC1 Call rejected,21,2,2016/04/06 17:40,EMPTY,RNC1 Call rejected,21,2,2016/04/06 17:40,EMPTY,RNC2 User alerting - no answer,19,176,2016/04/06 17:40,EMPTY,RNC3 No circuit/channel available,34,2,2016/04/06 17:40,EMPTY,RNC4 Call rejected,21,6,2016/04/06 17:40,EMPTY,RNC5

It is necessary to calculate the sum of the values ​​of the third variable from the lines in which the second variable is X (For example, 21). Further, when the maximum value of the third variable exceeds the specified value (for example, it should not exceed 10), all the lines involved in the calculation are sent to the administrator by e-mail.

  • This line - check with the teacher, which of the two. - aleksandr barakin
  • here you need a comparison with the number and if the result is above the number, then you need to throw off all the lines that contain the parameter 2nd parameter (2 stem), i.e. Permissible in this example, you need to throw off the first and second line. - Pavel
  • and what exactly you can not? - aleksandr barakin
  • In the trailer, I could only sum up the number of values ​​of the 3rd column, provided that the value coincides in 2, but in the end I cannot move further, I do not know what to do. Please help. - Pavel
  • You have received several sums. As far as I understand, you need to choose the maximum from them. - aleksandr barakin

2 answers 2

Something like this:

 #!/bin/bash #CONSTANTS MAIL_SUBJECT="Превышение значения" MAIL_TO="admin@domain.com" ZANCHENIE="10" #Получаем все нужные строки со вторыми переменными равными "ZNACHENIE" cat /root/file.input | grep .*\,$ZNACHENIE #Здесь производим нужные вычисления - вы указали #что смогли получить сумму третьих переменных if [[ $summa -gt $porog ]]; then cat /root/file.input | grep .*\,$ZNACHENIE >> /root/StringsToSend echo $MAIL_SUBJECT | cat - /root/StringsToSend | sendmail -t $MAIL_TO fi 
  • #! / bin / bash LDIFS = $ IFS IFS = "," echo "\ n" >> RNC_Rel.csv <br/> for i in 19 31 41 57 65 81 98 8 21 28 30 38 63 70 99 25 55 88 102 3 22 26 27 47 69 79 91 29 34 42 87 96 1 50 95 97 111 127 6 43 44 68 58 100 101 do eval sum $ i = 0 while read ccname cccode sumtran time rabcouse rncname <br/> do if [" $ cccode "-eq" $ i "]; then eval sum $ i = $ ((sum $ i + $ sumtran)) fi done <$ 1 if eval ["$ echo sum$i " -gt "100" -a "$ cccode" -eq "31"]; then echo "CC Code $ i" eval echo "Sum Tran" $ echo sum$i fi done IFS = $ OLDIFS ` - Pavel
  • @Pavel, what is it? You obviously have problems with formatting text. - Alexandr Blinov
  • Something I can’t enter here is how to format the comments here :) This is the part of the script that receives the sum of 3 variables based on the similarity of the 2nd. I can't get the $ echo sum$i variable into the if statement. Perhaps you can offer a different comparison option than mine? - Pavel
  • if possible, open PM in VK, it will be easier. Thank! - Pavel

I could only sum up the number of values ​​of the 3rd column, provided that the value coincides in 2, but in the end I cannot move on, I do not know what to do.

then it is necessary to compare this amount with the “threshold” value.

like that:

 if [[ $summa -gt $porog ]]; then нужные действия fi 

-gt - "more than." if you need “greater or equal”, use -ge . see man bash .

  • Not) The idea is the following file: Interworking - unspecified, 127,1,2016 / 04/06 17: 40, EMPTY, RNC1 <br> Call rejected, 21,2,2016 / 04/06 17: 40, EMPTY , RNC1 <br> Call rejected, 21,2,2016 / 04/06 17:40, EMPTY, RNC2 <br> User alerting - no answer, 19,176,2016 / 04/06 17: 40, EMPTY, RNC3 <br> No circuit / channel available, 34,2,2016 / 04/06 17: 40, EMPTY, RNC4 <br> Call rejected, 21,6,2016 / 04/06 17: 40, EMPTY, RNC5 <br> and so on , you need to do the following to take 2 parameter in each line, for example 21 (there will always be some number, all these numbers are known if they are needed) - Pavel
  • look for the whole line where the second parameter is 21, we’ve found it, then we need to add the value in all the found 3 lines of the parameter (or the column will be clearer :)) we finally got the value of this addition and suppose there is a condition for each value from the second column (of the parameter) there will be its limit value of the sum of the third column, suppose in this case there will be 5, i.e. adding all the values ​​by the second column parameter 21, - Pavel
  • we get the sum of the third column 10, then this parameter has exceeded the threshold and need all the lines that contain in the second column 21 to throw on email. and so you need to configure for different values ​​in the second column. Well, something like that) I hope not knowingly wrote) you can help :) Thank you! - Pavel
  • fine. You have stated virtually the same as me in the answer. those. you know the algorithm, but you don’t know how to implement one or another item from the algorithm. Ask specific questions using the button in the upper right corner of the page. - aleksandr barakin
  • @Pavel, I rewrote the answer. - aleksandr barakin