I'm trying to create a new variable array out of the unique values that are in another array but I'm not getting the desired result.
Original Array
# echo ${owner[*]}
390920ad-2858-e651-a4af-a9eaa6acaebb 390920ad-2858-e651-a4af-a9eaa6acaebb e14c2413-7179-44f8-dfc3-b8624dcb10bb 390920ad-2858-e651-a4af-a9eaa6acaebb e14c2413-7179-44f8-dfc3-b8624dcb10bb 390920ad-2858-e651-a4af-a9eaa6acaebb e14c2413-7179-44f8-dfc3-b8624dcb10bb 390920ad-2858-e651-a4af-a9eaa6acaebb 390920ad-2858-e651-a4af-a9eaa6acaebb 390920ad-2858-e651-a4af-a9eaa6acaebb e14c2413-7179-44f8-dfc3-b8624dcb10bb 390920ad-2858-e651-a4af-a9eaa6acaebb e14c2413-7179-44f8-dfc3-b8624dcb10bb 390920ad-2858-e651-a4af-a9eaa6acaebb 390920ad-2858-e651-a4af-a9eaa6acaebb 390920ad-2858-e651-a4af-a9eaa6acaebb 390920ad-2858-e651-a4af-a9eaa6acaebb 0a452389-5ed2-e46f-ad15-cc538c82650d 4232f23d-ed48-4b14-c0ea-aa911fd24920 8ee1b05f-2473-4c37-bfc5-ae393921b939
Command I'm using
uniq=($(printf "%s\n" "${owner[@]}" | sort -u))
Issue (It's storing all the unique values as a single value under index 0)
# echo ${uniq[0]}
0a452389-5ed2-e46f-ad15-cc538c82650d
390920ad-2858-e651-a4af-a9eaa6acaebb
4232f23d-ed48-4b14-c0ea-aa911fd24920
8ee1b05f-2473-4c37-bfc5-ae393921b939
e14c2413-7179-44f8-dfc3-b8624dcb10bb
# echo ${uniq[1]}
#
Anyone know a better way of grabbing the unique values from this array?
Using bash on SmartOS (Similar to Solaris)
EDIT
I've tried the following as well which will store each value under it's own index number but it does not remove the duplicate values:
uniq=($(printf "%s " "${owner[@]}" | sort -u))
IFS
variable does not include newline - have you modifiedIFS
? what version of bash is it? – steeldriver Jul 11 '17 at 21:55IFS=$' \t\n'
(That's a space, tab, newline.) – Wildcard Jul 11 '17 at 22:16