給未來的裕翔
如果現在我想要知道某個目錄以下(含子目錄)
的所有包含字串aaa的檔案
find target-dir -f file -exec grep -Hn aaa {} \;
-H是把檔名列出來
-n是把行數列出來
這樣就可以知道aaa在哪個檔案的哪個行數
Showing posts with label grep. Show all posts
Showing posts with label grep. Show all posts
Wednesday, August 18, 2010
Thursday, July 29, 2010
grep的正規表示式
給未來的裕翔
如果要在grep裡面用正規表示, ex:
grep '^\[.*\]' file 單引號可以
grep "^\[.*\]" file 雙引號可以
grep ^\[.*\] file 不加不可以
如果要在grep裡面用正規表示, ex:
grep '^\[.*\]' file 單引號可以
grep "^\[.*\]" file 雙引號可以
grep ^\[.*\] file 不加不可以
Tuesday, July 6, 2010
Sunday, March 28, 2010
grep的or功能
給未來的裕翔
如果要對某個檔案搜尋某個字
ex: 對/etc/passwd搜尋bob
grep bob /etc/passwd
那如果要對/etc/passwd搜尋bob或root呢?
因為或屬於extended-regexp
所以要用-E
grep -E 'bob|root' /etc/passwd
單引號務必要加, 否則會變成pipe
後記:
這樣也可以
給未來的裕翔
grep -e string1 -e string2 file
結論:
只有兩個字要搜尋的話
方法二會少一鍵
三個以上, 應該就是方法一比較少鍵了
超後記: 忘了上面的一切的 更未來的裕翔^^
egrep 'pattern1|pattern2' file
帥吧!
如果要對某個檔案搜尋某個字
ex: 對/etc/passwd搜尋bob
grep bob /etc/passwd
那如果要對/etc/passwd搜尋bob或root呢?
因為或屬於extended-regexp
所以要用-E
grep -E 'bob|root' /etc/passwd
單引號務必要加, 否則會變成pipe
後記:
這樣也可以
給未來的裕翔
grep -e string1 -e string2 file
結論:
只有兩個字要搜尋的話
方法二會少一鍵
三個以上, 應該就是方法一比較少鍵了
超後記: 忘了上面的一切的 更未來的裕翔^^
egrep 'pattern1|pattern2' file
帥吧!
Monday, March 22, 2010
快速知道哪些m檔非function
給未來的裕翔
剛下載了toolbox_sparsity.zip
裡面有個toolbox_sparsity資料夾
一堆m檔
大部分都是function
現在 我想知道"哪幾個m檔不是function"
我想到的方法是:
ls *.m > all-m-file.txt
grep function *.m > function-m-file.txt
diff all-m-file.txt function-m-file.txt
抓到啦 嘿嘿嘿
剛下載了toolbox_sparsity.zip
裡面有個toolbox_sparsity資料夾
一堆m檔
大部分都是function
現在 我想知道"哪幾個m檔不是function"
我想到的方法是:
ls *.m > all-m-file.txt
grep function *.m > function-m-file.txt
diff all-m-file.txt function-m-file.txt
抓到啦 嘿嘿嘿
Subscribe to:
Posts (Atom)