在Shell脚本中组织一系列数据(Organising A Range of Data in Shell Script)

我现在正面临一个两难的困境。 我需要取名字,他们的销售数字,并计算他们是否有权获得奖金和多少。 做这一切我很好!

THIS IS PSEUDO-CODE: read sales_rep read sales_total if $sales_total -gt 1000000 then echo '$sales_rep has a £1,500 bonus this quarter bonus = $1500 elif $sales_total -gt 100000 || $sales_total -lt 999999 then echo '$sales_rep has a £750 bonus this quarter bonus = £750 else echo '$sales_rep has no bonus this quarter' bonus = £0

这是我需要帮助的问题的第二部分。 我需要按季度销售顺序组织sales_person。 我只是将它们转储到一个数组中并显示出来。 但我不知道如何组织这个并将数据保持在一起。

任何帮助将非常感激。 有任何问题,请询问! 我可能不太清楚!

谢谢!

Would love some help with a dilemma I am facing right now. I need to take the name, their sales figure and calculate if they're entitled to a bonus and how much. I am fine with doing all of this!

THIS IS PSEUDO-CODE: read sales_rep read sales_total if $sales_total -gt 1000000 then echo '$sales_rep has a £1,500 bonus this quarter bonus = $1500 elif $sales_total -gt 100000 || $sales_total -lt 999999 then echo '$sales_rep has a £750 bonus this quarter bonus = £750 else echo '$sales_rep has no bonus this quarter' bonus = £0

It is the second part of the problem I need help with. I need to organise the sales_person in order of quarter sales. I was going to simply dump them in an array and display. But I have not idea how to organise this and keep the data together.

Any help would be hugely appreciated. Any questions, please ask! I may not have been clear!

Thanks!

最满意答案

您可以将用户,销售,奖金值输出为分隔字符串(例如,使用空格,除非您使用全名,在这种情况下使用逗号),并将结果传递给sort -rn -k2 。

所以如果你生成的输出

Alice,$964375,$750 Bob,$87234,$0 Carol,$1360263,$1500

然后你把它管道sort -rn -k2 -t, ,你会得到:

Carol,$1360263,$1500 Alice,$964375,$750 Bob,$87234,$0

You could output the user,sales,bonus values as delimited strings (say, with spaces, unless you're using full names, in which case try commas), and pipe the result to sort -rn -k2.

So if you generate output of

Alice,$964375,$750 Bob,$87234,$0 Carol,$1360263,$1500

and you then pipe that to sort -rn -k2 -t, , you will get:

Carol,$1360263,$1500 Alice,$964375,$750 Bob,$87234,$0在Shell脚本中组织一系列数据(Organising A Range of Data in Shell Script)

我现在正面临一个两难的困境。 我需要取名字,他们的销售数字,并计算他们是否有权获得奖金和多少。 做这一切我很好!

THIS IS PSEUDO-CODE: read sales_rep read sales_total if $sales_total -gt 1000000 then echo '$sales_rep has a £1,500 bonus this quarter bonus = $1500 elif $sales_total -gt 100000 || $sales_total -lt 999999 then echo '$sales_rep has a £750 bonus this quarter bonus = £750 else echo '$sales_rep has no bonus this quarter' bonus = £0

这是我需要帮助的问题的第二部分。 我需要按季度销售顺序组织sales_person。 我只是将它们转储到一个数组中并显示出来。 但我不知道如何组织这个并将数据保持在一起。

任何帮助将非常感激。 有任何问题,请询问! 我可能不太清楚!

谢谢!

Would love some help with a dilemma I am facing right now. I need to take the name, their sales figure and calculate if they're entitled to a bonus and how much. I am fine with doing all of this!

THIS IS PSEUDO-CODE: read sales_rep read sales_total if $sales_total -gt 1000000 then echo '$sales_rep has a £1,500 bonus this quarter bonus = $1500 elif $sales_total -gt 100000 || $sales_total -lt 999999 then echo '$sales_rep has a £750 bonus this quarter bonus = £750 else echo '$sales_rep has no bonus this quarter' bonus = £0

It is the second part of the problem I need help with. I need to organise the sales_person in order of quarter sales. I was going to simply dump them in an array and display. But I have not idea how to organise this and keep the data together.

Any help would be hugely appreciated. Any questions, please ask! I may not have been clear!

Thanks!

最满意答案

您可以将用户,销售,奖金值输出为分隔字符串(例如,使用空格,除非您使用全名,在这种情况下使用逗号),并将结果传递给sort -rn -k2 。

所以如果你生成的输出

Alice,$964375,$750 Bob,$87234,$0 Carol,$1360263,$1500

然后你把它管道sort -rn -k2 -t, ,你会得到:

Carol,$1360263,$1500 Alice,$964375,$750 Bob,$87234,$0

You could output the user,sales,bonus values as delimited strings (say, with spaces, unless you're using full names, in which case try commas), and pipe the result to sort -rn -k2.

So if you generate output of

Alice,$964375,$750 Bob,$87234,$0 Carol,$1360263,$1500

and you then pipe that to sort -rn -k2 -t, , you will get:

Carol,$1360263,$1500 Alice,$964375,$750 Bob,$87234,$0