Sorting and removing duplicate words in a line

前端 未结 7 1068
陌清茗
陌清茗 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:21

    Use python

    $ echo "zebra ant spider spider ant zebra ant" | python -c 'import sys; print(" ".join(sorted(set(sys.stdin.read().split()))))'
    ant spider zebra
    

提交回复
热议问题