[root@linux-node1 ~]# cat test.txt 1001 hisk01 1001 hisk02 1001 hisk03 1002 hisk04 1002 hisk05 1002 hisk06 1003 hisk07 1003 hisk08 [root@linux-node1 ~]# awk '{if($1==x){i=i" "$2}else{if(NR>1){print i};i=$0};x=$1;y=$2}' test.txt <(echo) 1001 hisk01 hisk02 hisk03 1002 hisk04 hisk05 hisk06 1003 hisk07 hisk08 [root@linux-node1 ~]# awk '{a[$1]=a[$1]?a[$1]" "$2:$2}END{for(i=0;i++<asorti(a,b);)print b[i],a[b[i]]}' test.txt 1001 hisk01 hisk02 hisk03 1002 hisk04 hisk05 hisk06 1003 hisk07 hisk08 [root@linux-node1 ~]#
$ cat ip_test.txt 192.0.0.1 test02 192.0.0.2 test03 192.0.0.1 test02 192.0.0.3 test04 192.0.0.2 test02 192.0.0.1 test02 192.0.0.1 test02 $ awk '{ip[$1]=ip[$1]" "$2} END {for(i in ip) print i, ip[i]}' ip_test.txt 192.0.0.3 test04 192.0.0.1 test02 test02 test02 test02 192.0.0.2 test03 test02