grep 擷取內容 - Linux

Table of Contents

grep "要搜尋的關鍵字" 檔案名稱

依照上面的例子,就可以將檔案內容符合關鍵字的行數,擷取出來

但是今天我想要多擷取關鍵字加上關鍵字的下一行

比如說:

test.txt內容如下:

receive Hello
Welcome to DSGH
Please tell me your ID


我下grep "Hello" test.txt

會秀出 receive Hello

但是有什麼方法可以

receive Hello
Welcome to DSGH

秀出關鍵字外的那一行加上下一行

謝謝

--

All Comments

Kelly avatarKelly2016-07-12
可以查 -A -B 參數,應該可以符合你的需求
Carolina Franco avatarCarolina Franco2016-07-15
先學會 man 跟 --help .....
google 一下發問的智慧你會得到 RTFM