Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

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

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

image

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


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

1 Answer

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'

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...