刪除匹配關鍵字的行和後幾行

text.txt:

37. Yahoo! Messenger: Chat (12) 

This scenario contains user-initiated operations of Yahoo! Messenger on a PC.  The user logs into Yahoo! Messenger, selects a friend, and initiates a chat with  the friend. The scenario ends after 3 minutes of user interactions. 
  
38. Yahoo! Messenger: Chat (11) 

This scenario contains user-initiated operations of Yahoo! Messenger on a PC.  The user logs into Yahoo! Messenger, selects a friend, and initiates a chat with  the friend. The scenario ends after 3 minutes of user interactions. 

sed '/This scena/,3d'
結果:

37.     Yahoo! Messenger: Chat (12) 
38.     Yahoo! Messenger: Chat (11) 


匹配命中關鍵字的後1行:

grep -A1 'keyword' test.txt

匹配命中關鍵字的前1行:

grep -B1 'keyword' test.txt


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章