bash - 如何从文本文件中删除部分重复项?

标签 bash awk sed grep

如何使用 awk、grep 或 sort 删除 bash 中的部分重复项?

输入:

"3","6"
"3","7"
"4","9"
"5","6"
"26","48"
"543","7"

预期输出:

"3","6"
"3","7"
"4","9"
"26","48"

最佳答案

您可以尝试关注并告诉我这是否对您有帮助。

awk -F'[",]' '!a[$5]++'   Input_file

输出如下。

"3","6"
"3","7"
"4","9"
"26","48"

编辑:也在此处添加解释。

awk -F'[",]' '   ##Setting field separator as " or , for every line of Input_file.
!a[$5]++         ##creating an array named a whose index is $5(fifth field) and checking condition if 5th field is NOT present in array a, so when any 5th field comes in array a then increasing its count so next time it will not take any duplicates in it. Since awk works on condition and then action, since here no action is mentioned so by default print of current line will happen.
' Input_file     ##Mentioning the Input_file here too.

关于bash - 如何从文本文件中删除部分重复项?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48031078/

相关文章:

regex - 如何仅删除所有以大写字母书写的单词(通过使用 sed 和/或 awk)

unix - 我必须更换所有的?在 unix 中使用 X 除了一些有效的?

linux - AWK:如何在不考虑回行的情况下提取两个 "\\"之间的文本 block

shell - 尾-f | sed 到文件不起作用

regex - 按模式查找线条,仅保留模式但保留不匹配的线条

android - 获取文件权限和父目录

bash - bash脚本将服务传递给变量

java - 如何添加自定义 Java 命令行选项?

bash - $HOME 与 ~ 用于 bash 脚本

regex - 无法使用正则表达式解析 bash 输出并收集其中的一部分