如何限制grep只搜索CSV文件中的一列,但输出匹配的行? [英] How to restrict grep to search only the one column within a CSV file, but to output matching lines in their entirety?
本文介绍了如何限制grep只搜索CSV文件中的一列,但输出匹配的行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何使用 grep
只搜索CSV文件中的一列,但在找到匹配项后,输出整行?例如:
How can I use grep
to search only one column within a CSV file, but after a match is found, to output the entire line? E.g.:
fish @ eats worms
bear @ eats fish
推荐答案
...使用awk ...
解决方案
...Use awk...
而不是shell的扩展。
To use a shell variable change single quotes to doubles and escape the awk variables (soo awk still sees $2 etc and not the shell's expansion of them.
awk -F@ "{if (\$2 ~ /$find_me/ ) { print \$0; } }" <input_file>
这篇关于如何限制grep只搜索CSV文件中的一列,但输出匹配的行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文