shell grep命令


 

grep選項與參數:
-a:將binary檔案以text檔案的方式搜尋數據
-c:計算找到’搜尋字符串’的次數
-i:忽略大小寫
-n:順便輸出行號
-v:反向選擇,亦即顯示出沒有’搜尋字符串’內容的那一行
--color=auto:可以將找到的關鍵字部分加上顏色顯示。color有三種參數(auto,always,never)
如果加上--color=never可以去掉顏色
[zhang@localhost ~]$ cat 1.txt 
hello world
abcdefg hijklmn
opqrst uvwxyz
abc
hello
world
HEllo1
hello2
world3
[zhang@localhost ~]$ cat 1.txt | grep hello
hello world
hello
hello2
搜索到的hello字段,默認紅色,如果加上--color=never可以去掉顏色。
添加-n參數,可以輸出行號。
[zhang@localhost ~]$ cat 1.txt | grep hello -n
1:hello world
5:hello
21:hello2
添加-i參數,忽略大小寫。
[zhang@localhost ~]$ cat 1.txt | grep hello -i
hello world
hello
HEllo1
hello2
|連續使用
[zhang@localhost ~]$ cat 1.txt | grep o | grep w
hello world
opqrst uvwxyz
world
world3

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM