简体   繁体   English

从bash数组中查找并显示唯一值

[英]Find and show unique value from bash array

If I have an array in bash like: 如果我在bash中有一个数组,如:

x=(1 1 1 2 2 3 3 4 5 5)

How do you determine and print the value that occurs only once? 如何确定并打印仅出现一次的值?

Try this: 试试这个:

printf "%s\n" "${x[@]}" | sort | uniq -u

Output: 输出:

4

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

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