输入文件
1 2 3 1 4 5 6 1 1 2 34 5 6 2
我希望输出这样
1 2 3 4 5 6 34
(所有重复的号码只能打印一次)
使用awk
(从整个文件中删除重复项):
awk '{ SEP=""; i=0;
while (++i<=NF) { printf (!unq[$i]++? SEP $i:""); SEP=" "};
print "";
}' infile
或分别从各行中删除重复项:
awk '{ SEP=""; i=0; delete unq;
while (++i<=NF) { printf (!unq[$i]++? SEP $i:""); SEP=" "};
print "";
}' infile
遍历号,如果以前没有见过,它添加到称为数组unq
和printf
它在其他打印什么。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句