linux cat命令查找文件内容

  1. grep -C 5 foo file 显示file文件里匹配foo字串那行以及上下5行  
  2. grep -B 5 foo file 显示foo及前5行  
  3. grep -A 5 foo file 显示foo及后5行  
  4.   
  5. -------------------------------------------------------------------------------------------------  
  6.   
  7.   
  8. grep结果太多, 可否只取前面10行匹配的结果  
  9. grep ...... | head -10  
  10. -------------------------------------------------------------------------------------------------  
  11.   
  12. 一、使用cat、tail、head组合  
  13. 1、查看最后1000行的数据  
  14. cat filename | tail -n 1000  
  15. 2、查看1000到3000行的数据  
  16. cat filename | head -n 3000 | tail -n +1000  
  17.   1、cat filename 打印文件所有内容  
  18.   2、tail -n 1000 打印文件最后1000行的数据  
  19.   3、tail -n +1000 打印文件第1000行开始以后的内容  
  20.   4、head -n 1000 打印前1000的内容  
  21. 二、使用sed命令  
  22. 显示1000到300行的数据  
  23. sed -n '1000,3000p' filename  
  24.   
  25.   
  26. https://blog.csdn.net/u011487593/article/details/52287991  
  27.   
  28. cat run.log.2018-06-01  |grep -C 10 '粤B7M61W'  

猜你喜欢

转载自ouyang.iteye.com/blog/2424103