排序和在一条线上去除重复的单词 [英] Sorting and removing duplicate words in a line

查看:108
本文介绍了排序和在一条线上去除重复的单词的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

排序命令让我把按字母顺序排列的线条和删除重复的线路。我需要类似的东西,但可以词语在一行(它是存储在一个变量)进行排序,将它们在顺序,并删​​除所有重复。是否有一个命令为这个?

The sort command lets me put lines in alphabetical order and remove duplicate lines. I need something similar, but that can sort the words on a single line (it is stored in a variable), putting them in order, and removing any duplicates. Is there a command for this?

例如:

zebra ant spider spider ant zebra ant

更改为:

ant spider zebra

有是第一个字前或最后一个单词后没有空格。

There is no space before the first word or after the last word.

推荐答案

这对我的作品:

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

您可以在一行中变换单词的列表,一列用的xargs -n1 ,使用排序-u 和改造回单一行的xargs

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.

这篇关于排序和在一条线上去除重复的单词的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆