awk之match函数

时间:2017-07-26 23:19:52   收藏:0   阅读:1025

格式:match(string,regexp,array)    和string~regexp的作用类似

说明:不依靠$1,2,3。。。来提取特定的列.

没有array的情况下:通过regexp,在string中寻找最左边,最长的substring,返回substring的index位置。

有array的情况下:在regexp中用()将要组成的array的内容按顺序弄好,a[1]代表第一个()的内容,a[2]代表第二个()的内容,以此类推。

echo "gene_type  "mrna";gene_name "typ""|awk ‘match($0,/(gene_type).+(".+?");gene_name/,a){print a[1]}‘
gene_type

echo "gene_type  "mrna";gene_name "typ""|awk ‘match($0,/(gene_type).+("+?");gene_nae/,a){print a[2]}‘
mrna

  

原文:http://www.cnblogs.com/timeisbiggestboss/p/7242351.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!