linux 中awk中match的使用

 

输出is和not后面的单词

001、

复制代码
[root@PC1 test01]# ls
a.txt
[root@PC1 test01]# cat a.txt    ## 测试数据
this is wang ,not wan
that is chen, not che
this is chen ,and wang ,not wan che
[root@PC1 test01]# awk '{match($0, /.+is([^,]+).+not(.+)/, a);print a[1],a[2]}' a.txt   ## 提取命令
 wang   wan
 chen  che
 chen   wan che
复制代码

 

复制代码
[root@PC1 test01]# ls
a.txt
[root@PC1 test01]# cat a.txt        ## 测试数据
this is wang ,not wan
that is chen, not che
this is chen ,and wang ,not wan che                               ## 只提取not后面的第一个单词
[root@PC1 test01]# awk '{match($0, /.+is([^,]+).+not( [^ ]+)/, a);print a[1],a[2]}' a.txt
 wang   wan
 chen  che
 chen   wan
复制代码

 

002、

[root@PC1 test01]# echo "abc123def456" | awk '{match($0, /[0-9]+/); print substr($0, RSTART, RLENGTH)}'
123        ## RSTART 和 RLENGTH是内置函数,表示匹配的起点和终点

 

 

来源:

https://blog.csdn.net/weixin_39568926/article/details/116705527

 

posted @   小鲨鱼2018  阅读(477)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· 上周热点回顾(3.3-3.9)
· winform 绘制太阳,地球,月球 运作规律
历史上的今天:
2022-08-07 linux 中 shasum命令
2022-08-07 python 中re包中 findall函数
2022-08-07 python 中统计fasta文件GC含量、总长度、总的GC含量
2022-08-07 python 中删除文本中指定的字符串
2022-08-07 python 统计fasta文件每条scalfold的碱基长度
2021-08-07 c语言中printf()函数的返回值
2021-08-07 c语言中printf()函数的转换说明修饰符
点击右上角即可分享
微信分享提示