edit:add-var cleankh~ {|@argv| use str use framagit.org/benjamin.vaudour/elv-lib/mods/common use framagit.org/benjamin.vaudour/elv-lib/mods/ip use framagit.org/benjamin.vaudour/elv-lib/mods/list fn sort-host {|e1 e2| var i1 = (common:cond (ip:is-ip $e1) 1 0) var i2 = (common:cond (ip:is-ip $e2) 1 0) if (!= $i1 $i2) { - $i1 $i2 } elif (== $i1 0) { compare $e1 $e2 } else { ip:comp $e1 $e2 } } var khosts = [&] cat ~/.ssh/known_hosts | eawk {|_ hosts @rest| var key = (str:join ' ' $rest) if (not (has-key $khosts $key)) { set khosts[$key] = [&] } str:split , $hosts | each {|h| set khosts[$key][$h] = $nil } } var lines = [(keys $khosts | each {|key| var hosts = (keys $khosts[$key] | list:sort $sort-host~ | str:join ,) put $hosts $key | str:join ' ' })] echo (str:join "\n" $lines) > ~/.ssh/known_hosts }