Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
4.0k views
in Technique[技术] by (71.8m points)

求帮助,txt里一组数值,带有符号。怎么用命令去重,并且输出不重复的数字。感谢!

image

上面一行数据,怎样让其中重复数字去掉,输出不重复的 类似这样“[175]/[176]/[177]/[178]”


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

假定你的数据源文件是 ls.txt, 经过下述步骤转换可达到你想要的效果
xargs 行转列 --> sort 去重排序 --> paste 多行合并 --> sed 正则替换

cat ls.txt |xargs -d [ -n 1 |sort -u |paste -d [ -s |sed 's/][/]/[/g'

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...