awk的match函数总结
来源:互联网 发布:在淘宝上怎么买开山刀 编辑:程序博客网 时间:2024/06/05 14:27
开始正文之前, 推荐下这里有个介绍awk数组的精华帖: http://bbs.chinaunix.net/thread-2312439-1-1.html
grep 1083628889 XXYY.TamServer_updateVipAmount_20121227.log | tr -d '][' | awk 'BEGIN{ FS="|" }{ match($10, / money=[0-9]+*/, a); match($10, / vip=[0-9]+*/, b); print $4,a[0],b[0] }'
match(s, r [, a])
Returns the position in s where the regular expression r occurs, or 0 if r is not present, and sets the values of RSTART and RLENGTH. Note that the argument order is the same as for the ~ operator: str ~ re. If array a is provided, a is cleared and then elements 1 through n are filled with the portions of s that match the corresponding parenthesized subexpression in r. The 0'th element of a contains the portion of s matched by the entire regular expression r. Subscripts a[n, "start"], and a[n, "length"] provide the starting index in the string and length respectively, of each matching substring.
两种用法:
1. 普通用法
match(字符串,正则表达式)
内置变量RSTART表示匹配开始的位置,RLENGTH表示匹配的长度
如果匹配到了,返回匹配到的开始位置,否则返回0
$ awk 'BEGIN{start=match("Abc Ef Kig",/ [A-Z][a-z]+ /);print RSTART,RLENGTH}'
4 4
2. 建立数组(If array a is provided, a is cleared and then elements 1 through n are filled with the portions of s that match the corresponding
parenthesized subexpression in r. The 0'th element of a contains the portion of s matched by the entire regular
expression r. Subscripts a[n, "start"], and a[n, "length"] provide the starting index in the string and length
respectively, of each matching substring.)
echo "foooobazbarrrrr | gawk '{ match($0, /(fo+).+(bar*)/, arr) #匹配到的部分自动赋值到arr中,下标从1开始
print arr[1], arr[2]
print arr[1, "start"], arr[1, "length"] #二维数组arr[index,"start"]值=RSTART
print arr[2, "start"], arr[2, "length"] #二维数组arr[index,"length"]值=RLENGTH
}'
foooo barrrrr
1 5
9 7
Returns the position in s where the regular expression r occurs, or 0 if r is not present, and sets the values of RSTART and RLENGTH. Note that the argument order is the same as for the ~ operator: str ~ re. If array a is provided, a is cleared and then elements 1 through n are filled with the portions of s that match the corresponding parenthesized subexpression in r. The 0'th element of a contains the portion of s matched by the entire regular expression r. Subscripts a[n, "start"], and a[n, "length"] provide the starting index in the string and length respectively, of each matching substring.
两种用法:
1. 普通用法
match(字符串,正则表达式)
内置变量RSTART表示匹配开始的位置,RLENGTH表示匹配的长度
如果匹配到了,返回匹配到的开始位置,否则返回0
$ awk 'BEGIN{start=match("Abc Ef Kig",/ [A-Z][a-z]+ /);print RSTART,RLENGTH}'
4 4
2. 建立数组(If array a is provided, a is cleared and then elements 1 through n are filled with the portions of s that match the corresponding
parenthesized subexpression in r. The 0'th element of a contains the portion of s matched by the entire regular
expression r. Subscripts a[n, "start"], and a[n, "length"] provide the starting index in the string and length
respectively, of each matching substring.)
echo "foooobazbarrrrr | gawk '{ match($0, /(fo+).+(bar*)/, arr) #匹配到的部分自动赋值到arr中,下标从1开始
print arr[1], arr[2]
print arr[1, "start"], arr[1, "length"] #二维数组arr[index,"start"]值=RSTART
print arr[2, "start"], arr[2, "length"] #二维数组arr[index,"length"]值=RLENGTH
}'
foooo barrrrr
1 5
9 7
0 0
- awk的match函数总结
- awk的match函数总结
- awk字符串函数总结
- match函数的用法
- shell 函数 awk函数总结
- linux awk常用函数总结
- awk的内置函数
- @awk的gsub函数@
- awk的split函数
- awk 的时间函数
- Match函数的典型用法
- shell函数和awk函数总结
- awk的使用记录总结
- awk的内建函数
- awk 的内置字符串函数
- awk数据处理的几个函数
- awk 的內建函数
- PowerBuilder 8.0 函数Match的bug
- C# Hashtable的遍历
- lipo命令,给你的应用程序瘦身
- 第11周项目二 求最大公约数
- MySQL 5.6 for Windows 解压缩版配置安装
- Android 多点触摸输入
- awk的match函数总结
- SQL Server Profiler使用教程,通俗易懂才是王道
- 【Leetcode】Two Sum (Sum)
- Eclipse打包mapreduce程序并提交至hadoop集群运行
- 计划应该制定得轻松
- Reporting Services 中 Web服务URL 与 报表管理器URL
- Xcode 封装 .Bundle 文件
- HttpUrlConnection与HttpClient的区别 无代码
- PIL Image模块 show函数不能正常显示图片