linux中grep基本用法
生活随笔
收集整理的這篇文章主要介紹了
linux中grep基本用法
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
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
總結
以上是生活随笔為你收集整理的linux中grep基本用法的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: disconf-自动注入属性变化
- 下一篇: linux 再多的running也挡不住