awk print rows of CSV file on condition?

时间:2015-06-25 18:44:12

标签: linux shell awk sed

I have a CSV file that has this values: A B C 1 cat cat 2 mouse pig 3 dog dog How can i write an awk code that only prints rows where col A = col C? Output i hope to get: A B C 1 cat cat 3 dog dog

2 个答案:

答案 0 :(得分:4)

That is pretty simple $ awk '$2==$3' file 1 cat cat 3 dog dog $2==$3 Checks if the second field, $2 is equal to third field, $3. If yes, awk takes the default action to print the entire record, line.

答案 1 :(得分:0)

awk'!/ 2 / {print $ 0}'文件
A B C
1只猫猫
3只狗狗

已实现我必须查看高级帮助才能按顺序获取输出,但是对于制表机来说却失败了。

克拉斯

相关问题