docker三劍客,01-07 Linux三劍客-grep

 2023-10-06 阅读 28 评论 0

摘要:定義 根據用戶指定的模式(pattern),對目標文件進行過濾,顯示被漠視匹配到的行 格式:grep [參數] 匹配內容 [文件] 常用參數: -v:顯示未匹配到的行-i:忽略大小寫-n:顯示匹配的行號-c:統計匹配的行數-o&

定義

根據用戶指定的模式(pattern),對目標文件進行過濾,顯示被漠視匹配到的行

格式:grep [參數] 匹配內容 [文件]

常用參數:

  • -v:顯示未匹配到的行
  • -i:忽略大小寫
  • -n:顯示匹配的行號
  • -c:統計匹配的行數
  • -o:僅顯示匹配到的字符串
  • -E:使用 ERE,相當于 egrep

實戰應用:

  • 顯示含有 root 的行,并顯示行號
$ cat test
root root hello root
new
new
root
root
leo
kate
hogwart
string
leon
$ grep -n root test
1:root root hello root
4:root
5:root
  • 顯示不包含 root 的行,并顯示行號
$ grep -vn root test
2:new
3:new
6:leo
7:kate
8:hogwart
9:string
10:leon
  • 查找以 s 開頭的行;查找以 n 結尾的行
$ grep ^s -n test
9:string
$ grep n$ -n test
10:leon

版权声明:本站所有资料均为网友推荐收集整理而来,仅供学习和研究交流使用。

原文链接:https://hbdhgg.com/3/121025.html

发表评论:

本站为非赢利网站,部分文章来源或改编自互联网及其他公众平台,主要目的在于分享信息,版权归原作者所有,内容仅供读者参考,如有侵权请联系我们删除!

Copyright © 2022 匯編語言學習筆記 Inc. 保留所有权利。

底部版权信息