简体   繁体   English

外壳按字母顺序对输出进行排序

[英]SHELL Sorting output alphabetically

I have a script with output for example acd txt iso ez I need to sort it alphabetically. 我有一个脚本,例如acd txt iso ez输出,我需要按字母顺序对其进行排序。 These are file extensions so I cant compile it together in one word and then split up. 这些是文件扩展名,所以我不能用一个词将其编译在一起,然后拆分。 Can anyone help me? 谁能帮我?

If your the name of your script is foo and it writes to stdout a string such as acd txt iso ez , you can get the sorted list by, for instance: 如果您的脚本名称为foo并且它向stdout中写入了acd txt iso ez之类的字符串,则可以通过以下方式获取排序列表:

sorted_output=$(foo|xargs -n 1|sort)

Of course, depending on what you are going to do with the result, it might make more sense to store it into an array. 当然,取决于对结果的处理方式,将其存储到数组中可能更有意义。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM