当前位置:网站首页>常见Shell命令 - grep(一)
常见Shell命令 - grep(一)
2022-04-21 18:57:00 【shang_xs】
常见Shell命令 - grep(一)
grep命令
参数释义
- -v 不显示匹配行信息
- -i 搜索时忽略大小写
- -n 显示行号
- -r 递归搜索
- -E 支持扩展正则表达式
- -F 不按正则表达式匹配,按照字符串字面意思匹配
使用形式
形式一
grep [option] [pattern] [file1,file2,file3…]
形式二
command | grep [option] [pattern]
案例实操
添加文件
- 内容见下文
查询文件所有内容
$ cat grep.txt
study command for grep
study command for grep file
study command for egrep
study command for tail
study command for vim
study command for rm
查询包含grep的行
$ grep ‘grep’ grep.txt
study command for grep
study command for grep file
study command for egrep
- 追加文本内容,全文如下:
study command for grep
study command for grep file
study command for egrep
study command for tail
study command for vim
study command for rm
study command for GREP
查询不包含grep的行,忽略大小写
$ grep -v ‘grep’ grep.txt
study command for tail
study command for vim
study command for rm
study command for GREP
查询不包含grep的行,不忽略大小写
$ grep -vi ‘grep’ grep.txt
study command for tail
study command for vim
study command for rm
查询包含grep的行,包含在文件中的行号
$ grep -n ‘grep’ grep.txt
1:study command for grep
2:study command for grep file
3:study command for egrep
-E 支持扩展正则表达式,查找包含grep或tail的行
$ grep -E ‘grep|tail’ grep.txt
study command for grep
study command for grep file
study command for egrep
study command for tail
只显示匹配到的行数
$ grep -c ‘grep’ grep.txt
3
egrep
说明: 和 grep使用方式一样, 功能更加强大,支持正则
$ egrep ‘grep|tail’ grep.txt
study command for grep
study command for grep file
study command for egrep
study command for tail
与 、或总结
与条件
$ grep ‘egrep’ grep.txt | grep ‘study’
study command for egrep
或条件
$ grep ‘grep|study’ grep.txt
study command for grep
study command for grep file
study command for egrep
study command for tail
study command for vim
study command for rm
study command for GREP
版权声明
本文为[shang_xs]所创,转载请带上原文链接,感谢
https://blog.csdn.net/shang_xs/article/details/124321069
边栏推荐
- Qianxin monitoring equipment --- Jiaotu
- SVG系列——2,绘制一些形状
- TypeScript快速上手,class,public,private,extends
- 无线蓝牙耳机哪款比较好用?2022蓝牙耳机推荐
- 论持续发展创客教育的意义
- spfa判断是否存在负环
- Crystal Chem小鼠葡萄糖检测试剂盒说明书
- Log4j log usage
- What brand of wireless headphones has the best quality? Recommended Bluetooth headset with good reputation
- Database advanced learning: storage engine
猜你喜欢

LeetCode1765. 地图中的最高点(BFS)

Database advanced learning: index classification and creation syntax

大厂推荐使用的网关解密:Fizz Gateway后台管理系统功能模块介绍

NMI paper by payel DAS and others of IBM Research Institute: general machine learning framework for optimizing molecules

Developer tools top 100 list

【ES6】let、const、解构赋值、模板字符串
![[04] [01] [01] redis Basics](/img/35/835ea69773be0ca6c238ffa3d33b2a.png)
[04] [01] [01] redis Basics

How much can I get a month with a PMP certificate
![[games101] assignment 5: simple ray tracing and framework understanding](/img/d2/31a20ea3848035fcdf8db9b883cc80.png)
[games101] assignment 5: simple ray tracing and framework understanding
![[04][02][02] SPI 机制](/img/62/c9852086e7893d392ef407c294dd1e.png)
[04][02][02] SPI 机制
随机推荐
编程中的Context(上下文)
Dry goods | after the interview, how to talk about salary? What are the skills of a high paying offer?
Understand the new economic model of platofarm and its ecological progress
JVM class loading mechanism
Semaphore and exchange of concurrent tools
Abbexa MPO (FITC) / CD3 (PE) 组合抗体
Major event review Carnival link construction
【深度之眼】情感分析——循环神经网络用于多任务学习的文本分类TextRNN
VB judges whether a number is a prime number.
What's a good brand of real wireless headphones? High profile flagship Bluetooth headset
T-SQL language of SQL Server database
Daily question series: shuffle
MKL库矩阵乘法
数据库进阶学习:索引介绍及Btree,B+tree,hash
el-tabs中套用el-tooltip(气泡文字提示框)
手把手教會你搭建組件與應用
Database advanced learning: introduction to index and BTREE, B + tree, hash
ssh-keygen 设置免密登录
Cvpr2022 unified upgrade of oral | cosface and arcface, and adaface solves face recognition of low-quality images
Tiandan released the cloud native intelligent operation and maintenance product line and launched the world's first full stack observability technical standard