unique inside array

I have a file

root@server [~]# cat /root/list12
11.22.33.44
22.33.44.55
33.44.55.66
33.44.55.66
33.44.55.66

I try to pass to array and display unique.

root@server[~]# cat /root/test12.sh
#!/bin/bash

#delcare array badips and accumulate values to array elemenrs
badips=( $( cat /root/list12 | while read entry
do
                echo -e "\n $entry"

done ) )

echo ${badips[@]/%/ --- }

But output is


root@server [~]# /root/test12.sh
11.22.33.44 --- 22.33.44.55 --- 33.44.55.66 --- 33.44.55.66 --- 33.44.55.66 ---

I need uniq entire only. No repitition.

Desired output.

11.22.33.44 --- 22.33.44.55 --- 33.44.55.66

Hi

uniq /root/list12 | sed -e :a -e 'N;s/\n/ -- /;ta'

Guru.

1 Like

uniq needs sorted input.

awk 'END{printf RS} !A[$1]++' ORS=" --- " infile
1 Like
awk '!a[$1]++' infile | xargs | sed 's/ / --- /g'

Thanks guys