cat、tail、head、grep查文件

grep -C 5 foo file 显示file文件里匹配foo字串那行以及上下5行
grep -B 5 foo file 显示foo及前5行

grep -A 5 foo file 显示foo及后5行

-------------------------------------------------------------------------------------------------

grep结果太多, 可否只取前面10行匹配的结果
grep ...... | head -10
-------------------------------------------------------------------------------------------------

一、使用cat、tail、head组合

1、查看最后1000行的数据

cat filename | tail -n 1000
2、查看1000到3000行的数据

cat filename | head -n 3000 | tail -n +1000

  1、cat filename 打印文件所有内容
  2、tail -n 1000 打印文件最后1000行的数据
  3、tail -n +1000 打印文件第1000行开始以后的内容
  4、head -n 1000 打印前1000的内容

猜你喜欢

转载自blog.csdn.net/qyt0147/article/details/79197700