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