linux下查找文件中某字符串出现的行数以及该行的前后N行

mac2025-04-15  7

第一种

grep -A 100 -B 100  'ORA-00600' alert_orcl1.log -A after 后面 -B before 前面

 

第二种

grep -in 'ORA-00600' alert_orcl1.log |head -1

返回行数 1974220:ORA-00600 ... sed -n '1974210,1974220p' alert_orcl1.log

查看文件的1974210-1974220行

 

第三种

grep -C 5 'ORA-00600' alert_orcl1.log 显示file文件里匹配字串那行以及上下5行

最新回复(0)