user982599
user982599

Reputation: 975

Find and show unique value from bash array

If I have an array in bash like:

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

How do you determine and print the value that occurs only once?

Upvotes: 3

Views: 716

Answers (1)

Cyrus
Cyrus

Reputation: 88553

Try this:

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

Output:

4

Upvotes: 4

Related Questions