当前位置:网站首页>grep 精确匹配
grep 精确匹配
2022-06-29 12:39:00 【51CTO】
使用grep实现精确过滤的五种方法
(1)当被过滤的内容占据一行时
[[email protected] scripts]# cat oldboy.log
200
0200
2000
[[email protected] scripts]# grep "\b200\b" oldboy.log
200 #<==正则按单词匹配
[[email protected] scripts]# grep -w "200" oldboy.log
200 #<==按单词匹配
[[email protected] scripts]# grep -x "200" oldboy.log
200 #<==按整行匹配
[[email protected] scripts]# grep "^200$" oldboy.log
200 #<==正则开头结尾匹配,相当于整行匹配
[[email protected] scripts]# grep -E "\<200\>" oldboy.log
200 #<==扩展正则
(2)当被过滤的内容占据一行的一部分
[[email protected] scripts]# cat oldboy.log
200 oldboy
0200 oldgirl
2000 littleboy
[[email protected] scripts]# grep "\b200\b" oldboy.log
200 oldboy
[[email protected] scripts]# grep -w "200" oldboy.log
200 oldboy
[[email protected] scripts]# grep -x "200" oldboy.log
#<==按整行匹配,所以没结果
[[email protected] scripts]# grep -x "200 oldboy" oldboy.log
200 oldboy
[[email protected] scripts]# grep "^200$" oldboy.log
#<==按整行匹配,所以没结果
[[email protected] scripts]# grep "^200 oldboy$" oldboy.log
200 oldboy
[[email protected] scripts]# grep -E "\<200\>" oldboy.log
200 oldboy
边栏推荐
- 【云驻共创】通过Rust语言计算加速技术突破图片识别性能瓶颈
- Learn from the official motor and BLDC control strategies, and make money as soon as you learn
- CVPR2022 | 长期行动预期的Future Transformer
- Detailed explanation of PDB symbol library files
- How to set the safety line and safety margin for futures trading?
- 项目管理复习题
- MySQL tuning
- 想做个答题类的微信小游戏?读这篇文章就够了
- Package folders as ISO
- Openssl证书工具使用手册
猜你喜欢

想做个答题类的微信小游戏?读这篇文章就够了

Yyds dry inventory solution sword finger offer: find the nearest common ancestor of two nodes in the binary tree

matplotlib的imshow函数显示灰度图像要设置vmin和vmax2个参数

【毕业季】这四年一路走来都很值得——老学长の忠告

Force buckle: merging two ordered linked lists

Qitai observation: professional elites must step on the huge pit of entrepreneurship - learning effect pit

Cisco simulator simple campus network design, final assignment difficulty

Three best practices help enterprises improve supply chain security

Why is the integration of storage and computing a new direction of core making Collision school x Zhicun Technology

#yyds干货盘点# 解决剑指offer:在二叉树中找到两个节点的最近公共祖先
随机推荐
MySQL常用语句和命令汇总
Install the terrain ovirt plug-in to provide automated management for ovirt
@Table爆红
云原生(三十一) | Kubernetes篇之Kubernetes平台基本预装资源
The former security director of Uber faced fraud allegations and concealed the data leakage event
Windbg常用命令详解
win32版俄罗斯方块(学习MFC必不可少)
Tree array application (acwing 24224244)
Qitai observation: professional elites must step on the huge pit of entrepreneurship - learning effect pit
Code tidiness learning notes
Imile uses Zadig's multi cloud environment to deploy thousands of times a week to continuously deliver global business across clouds and regions
记一次 .NET 某物管后台服务 卡死分析
Repoptimizer: it's actually repvgg2
matplotlib的imshow函数显示灰度图像要设置vmin和vmax2个参数
Prometheus 2.28.0 新特性
Pod security policy (PSP)
CVPR2022 | 重新审视池化:你的感受野不是最理想的
Uber前安全主管面临欺诈指控 曾隐瞒数据泄露事件
Is it safe to open an account online?
Exploring the way of automated testing - Preparation