平凡的幸福
撇開習慣,發現幸福就在平凡之中。 記錄生活、學習心得、工作遇到的問題與想法。
(移至...)
首頁
▼
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
‹
›
首頁
查看網路版