Sorting and removing duplicate words in a line

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

    Use tr to change spaces to new lines, then sort, and finally change new lines back to spaces.

    echo $(tr ' ' '\n' <<< "zebra ant spider spider ant zebra ant" | sort -u)
    

提交回复
热议问题