2016-09-13 39 views

回答

1

使用awkprocess-substitution只能比使用sort和其他工具。

awk -vORS="," '!seen[$1]++' < <(echo "[email protected],[email protected],[email protected],[email protected],[email protected]" | tr ',' '\n') 
[email protected],[email protected],[email protected] 

或者另一種方式來使用純bash和避免tr完全是

# Read into a bash array with field-separator as ',' read with '-a' for reading to an array 
IFS=',' read -ra myArray <<< "[email protected],[email protected],[email protected],[email protected],[email protected]" 


# Printing the array elements new line and feeding it to awk 
awk -vORS="," '!seen[$1]++' < <(printf '%s\n' "${myArray[@]}") 
[email protected],[email protected],[email protected] 
相關問題