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
分类:
linux shell
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 震惊!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()函数的转换说明修饰符