Sorting and removing duplicate words in a line

前端 未结 7 1073
陌清茗
陌清茗 2020-12-03 06:50

The sort command lets me put lines in alphabetical order and remove duplicate lines. I need something similar that can sort the words on a single line, put them

7条回答
  •  星月不相逢
    2020-12-03 07:28

    This works for me:

    $ echo "zebra ant spider spider ant zebra ant" | xargs -n1 | sort -u | xargs
    ant spider zebra
    

    You can transform a list of words in a single row to a single column with xargs -n1 , use sort -u and transform back to a single row with xargs.

提交回复
热议问题