awk的部分字符串匹配(如柱部分匹配) [英] awk partly string match (if column partly matches)

查看:370
本文介绍了awk的部分字符串匹配(如柱部分匹配)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的虚拟文件看起来是这样的:

  C1 C2,C3
1雪
2 B雪人
雪Çsowman

我要得到行,如果有字符串在$ 3我能做到这一点是这样的:

 的awk'($ 90元==雪花|| $ 3 ==雪人){}打印dummy_file

但应该有更多更简单的方法。


解决方案

 的awk'$ 3〜/雪景/ {}打印dummy_file

看一看O'Reilly的教程:

<一个href=\"http://oreilly.com/catalog/unixnut3/chapter/ch11.html\">http://oreilly.com/catalog/unixnut3/chapter/ch11.html

My dummy file looks like this:

C1    C2    C3    
1     a     snow   
2     b     snowman 
snow     c     sowman

I want to get line if there is string snow in $3. I can do this like this:

awk '($3=="snow" || $3=="snowman") {print}' dummy_file

But there should be more simpler way.

解决方案

awk '$3 ~ /snow/ { print }' dummy_file 

Have a look at the o'Reilly tutorials:

http://oreilly.com/catalog/unixnut3/chapter/ch11.html

这篇关于awk的部分字符串匹配(如柱部分匹配)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆