Linux grep找出前一行、後一行的字串

Linux的grep有參數-B、-A,可以取出符合搜尋條件行的前、後行字串。

例如:
[ly@oel6 ~]$ cat test.txt
abc
def
hij

取出後一行
[ly@oel6 ~]$ grep "d" -A1 test.txt
def
hij

取出前一行
[ly@oel6 ~]$ grep "d" -B1 test.txt
abc
def

取出前、後各一行
[ly@oel6 ~]$ grep "d" -A1 -B1 test.txt
abc
def
hij

Oracle DB的listener.log清理