Artificial intelligent assistant

How would you merge identical entries in the first column into one entry Have a file where the entries are all over the place. Example: 10.11.12.13 tiger adfa afinhhdddd tiger 10.11.12.13 tiger tiger 123 10.11.12.13 tiger abc 10.11.12.13 tiger abc 10.11.12.13 TIGER ABC 20.21.22.23 hola hola hola123 upside down 20.21.22.23 hola hola hola123 upside DOWN HOLA 20.21.22.23 hola hola hola123 upside down The final output should look like this: 10.11.12.13 tiger abc 123 adfa afinhhdddd 20.21.22.23 hola hola123 upside down

What you appear to want has little to do with sorting, but can be achieved by creating a hash (associative array) keyed on the values of the first column, into which you push case-converted copies of the other columns - which you then de-duplicate and print. In Perl for example


perl -MList::MoreUtils=uniq -alne '
push @{ $h{shift @F} }, map { lc $_ } @F if $_ =~ /\S/
}{
foreach $k (sort keys %h) {
print "$k\t", join " ", uniq @{ $h{$k} }
}
' file


Ex.:


$ perl -MList::MoreUtils=uniq -alne '
push @{ $h{shift @F} }, map { lc $_ } @F if $_ =~ /\S/
}{
foreach $k (sort keys %h) {
print "$k\t", join " ", uniq @{ $h{$k} }
}
' file
10.11.12.13 tiger adfa afinhhdddd 123 abc
20.21.22.23 hola hola123 upside down


If you want a specific order in the output of the array elements, then you will need to provide a rule for that.

xcX3v84RxoQ-4GxG32940ukFUIEgYdPy 24545cc04ee7607f0c6eec74892674e5