grep 查找并且提取文件内容
常用的匹配模式
hello 包含字符hello
^hello 以字符串hello开头
hello$ 以字符串hello结尾
语法格式
grep "条件" 文件名称
例:
1.在/hello/a.txt文件中找出包含 hello 的行
grep "hello" /hello/a.txt
hello
11 hello2
2.在/hello/a.txt文件中找出以 hello开头的行
grep "^hello" /hello/a.txt
hello
3.在/hello/a.txt文件中找出以hello结尾的行
# grep "hello$" /hello/a.txt
hello
4.在/hello/a.txt文件中找出以hello开头的行,并且写入到b.txt文件中
grep "^hello" /hello/a.txt > b.txt
[root@hello hello]# cat b.txt
hello
继续阅读与本文标签相同的文章
-
Spring Boot 2.x (一):第一个 Web 应用 Hello Spring Boot 2
2026-05-25栏目: 教程
-
重温 ES6 Symbol
2026-05-25栏目: 教程
-
初识数据库
2026-05-25栏目: 教程
-
.Net程序员必备-打印版Visual C#(VB) 2008 快捷键索引
2026-05-25栏目: 教程
-
在应用程序级别以外使用注册为 allowDefinition='MachineToApplication' 的节是错误的解决办法
2026-05-25栏目: 教程
