功能:match函数是用于个性化定制搜索模式。

例子:

文件内容:

this is wang ,not wan

that is chen, not che

this is chen ,and wang ,not wan che

思路:

比如你想提取is后面的第一个单词,和not 后面的第一个单词,

这时候利用位置来提取是不可行的,因为第三行的模式和前两行不一致,这种情况在基因注解里经常会碰到。

这是就可以用awk的match函数啦!!

[wangjq@mgmt humandb]$ cat test
this is wang,not wan
that is chen,not che
this is chen,and wang,not wan che
[wangjq@mgmt humandb]$ awk '{match($0,/.+is([^,]+).+not(.+)/,a);print a[1],a[2]}' test
wang wan
chen che
chen wan che

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

没有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

  

awk之match函数的更多相关文章

  1. linux awk 内置函数详细介绍(实例)

    这节详细介绍awk内置函数,主要分以下3种类似:算数函数.字符串函数.其它一般函数.时间函数 一.算术函数: 以下算术函数执行与 C 语言中名称相同的子例程相同的操作: 函数名 说明 atan2( y ...

  2. linux awk 内置函数实例

    awk内置函数,主要分4种:算数函数.字符串函数.时间函数.一般函数 一.算术函数 以下算术函数执行与 C 语言中名称相同的子例程相同的操作: 函数名 说明 atan2( y, x ) 返回 y/x ...

  3. match函数

    match(s, r [, a]) Return the position in s where the regular expression r occurs, or 0 if r is not p ...

  4. linux awk 内置函数详细介绍(实例)

    这节详细介绍awk内置函数,主要分以下3种类似:算数函数.字符串函数.其它一般函数.时间函数 一.算术函数: 以下算术函数执行与 C 语言中名称相同的子例程相同的操作: 函数名 说明 atan2( y ...

  5. awk内置函数、外部变量

    外部变量 ①获取外部变量 格式: awk '{action}' 变量名=变量值 ,这样传入变量可以在action中获得值. 示例: test='awk test'--day-5 外部变量 ①获取外部变 ...

  6. index+match函数在压实度中对盒号盒质量随机不重复的最佳使用

    首先按照升序排列好盒号和盒质量,使其一一对应, 盒号    盒重量    随机值rand()     随机值大小排列rank 1         2001       0.01             ...

  7. Excel——MATCH函数

    使用 MATCH 函数在范围单元格中搜索特定的项,然后返回该项在此区域中的相对位置. 1.参数说明: MATCH(lookup_value, lookup_array, [match_type]) l ...

  8. EXCEL 2010学习笔记 —— VLOOKUP函数 嵌套 MATCH 函数

    match index vlookup 等函数都是查找引用类函数,需要查找的时候关键变量只有两个,区域+位置,区域的选择注意是否需要锁定,位置的确定可以通过输入特定的行号和列号. match() ma ...

  9. js match函数注意

    match函数 String.prototype.match 参数 regexp 返回 返回包含所有匹配的数组,如果匹配失败返回Null. 数组第一项是整段字符串的匹配,第二项至以后都是捕获匹配. 注 ...

随机推荐

  1. YARN Architecture

    The fundamental idea of YARN is to split up the functionalities of resource management and job sched ...

  2. Sorted sets

    Redis in Action JOSIAH L. CARLSON MANNING Shelter Island ZSETs offer the ability to store a mapping ...

  3. MYSQL 命令行显示乱码 解决方案

    中文乱码是因为编码集不支持,所以要改变编码 先查看下设置的编码 使用如下命令 show variables like 'character%'; 在 mysql.conf (Ubuntu mysql5 ...

  4. GP服务中无Tasks

    发布GP服务,之后执行GP服务时,发现无Tasks,如下图所示 正常情况应该如下图 问题原因在于,arcmap与server版本不一致~~ (10.4.1arcmap 与 10.2.2 server) ...

  5. LightOJ 1027 - A Dangerous Maze(求期望)

    题目链接:http://lightoj.com/volume_showproblem.php?problem=1027 题意:又一个迷宫,有n个门,每个门又一个值num,如果num>0 说明在n ...

  6. Parity game---poj1733

    Description Now and then you play the following game with your friend. Your friend writes down a seq ...

  7. CentOS关闭防火墙&SELinux

    须知: 防火墙配置文件:/etc/sysconfig/iptables 查看防火墙状态:service iptables status 关闭防火墙:service iptables stop 关闭ip ...

  8. operator, itertools

    import operator import itertools info_list = [ {'name': 'Quinn', 'age': 50}, {'name': 'Ryan', 'age': ...

  9. Sql Server索引的原理与应用

    SqlServer索引的原理与应用 转自:http://www.cnblogs.com/knowledgesea/p/3672099.html   索引的概念 索引的用途:我们对数据查询及处理速度已成 ...

  10. display:table和display:table-cell结合使用

    .GoodList{ display :table; height :54px; width :56px; line-height: 14px                 padding: 0 1 ...