22. 使用 awk / grep / head / tail 命令进行文本

  • 时间:
  • 浏览:0
  • 来源:大发幸运飞艇APP下载_大发幸运飞艇APP官方

    [D@Demon ~]$ head -n 3 acc.log

二、head

1、head 命令参数

    D@Demon ~]$ awk '$7>0.007' acc.log | wc -l   (-l 表示统计有有几个行)

    -l            统计行数

    # 获取前 3 条日志

    -n            指定获取有几个行

2014-07-17 16:40:13 14478 127.0.0.1 461BE11327FCDCD9 m-close-file 0.019908 0 ax_put:0.001,ax_add_blk:0.012,aesenc:0.000,ax_get_blk:0.001,mx_get_file:0.003,use_sha1ctx:0.000,size:0.000 fdid:10,nmid:1885573511091757896,fid:19-1405586413 res:ax_add_blk.da39a3ee5e6b4b0d3255bfef955001890afd500709,1.ax_put.da39a3ee5e6b4b0d3255bfef955001890afd500709.0.0,ax_get_blk.da39a3ee5e6b4b0d3255bfef955001890afd500709,mx_get_file.19-1405586413

    50000 acc.log

    -q            隐藏文件名

2、head 使用

2014-07-17 16:56:20 14477 127.0.0.1 B8D40F03481F9881 m-write-file 0.017265 0 x_get_part:0.001,mx_update_part_sha1:0.012,aesenc:0.000,nparts:0.000,sha1ctx:0.000,sha:0.000,mx_write:0.000,mx_get_file:0.003,assureblks:0.000,rpost:0.000 hash:cfa211339753f9e6af4b9a35224be776a0f97b07,pos:0,fid:52-14055873500,size:4096 res:mx_get_part.52-14055873500.0,mx_get_file.52-14055873500,mx_update_part_sha1.52-14055873500.0.4096,1.mx_write.52-14055873500-0.0.4096

2014-07-17 16:40:13 14477 127.0.0.1 72CA0245933664A5 m-info-file 0.004441 0 mx_get_file:0.004 fid:19-1405586413 res:mx_get_file.19-1405586413

    [D@Demon ~]$ wc -l acc.log

    [D@Demon ~]$ tail -3 acc.log

四、wc 

2、统计 acc.log 有有几个行

# 统计 a-read-file 接口 中,接口耗时 超过 0.007 秒的有有几个个请求

    2014-07-17 16:40:13 14477 127.0.0.1 4FCD5690BB5FF879 m-create-file 0.022945 0 ax_add_file:0.003,mx_add_part:0.015,mx_create:0.002 fid:19-1405586413 res:ax_add_file.19-      405586413,mx_add_part.19-1405586413.0,1.mx_create.19-1405586413-0.0.83885008

    -v            输冒出示文件的文件名

    # 获取最后 3 条日志

    404

    -c           统计字节数

2014-07-17 16:56:20 14478 127.0.0.1 AB214643262BAE4E m-write-file 0.018161 0 mx_get_part:0.001,mx_update_part_sha1:0.012,aesenc:0.000,nparts:0.000,sha:0.000,mx_write:0.000,mx_get_file:0.003,assureblks:0.000,rpost:0.000 hash:972a2132d5006708d586540b4822681ec43188148,pos:0,fid:52-14055873500,size:4096 res:mx_get_part.52-14055873500.0,mx_get_file.52-14055873500,mx_update_part_sha1.52-14055873500.0.-1,1.mx_write.52-14055873500-0.0.4096

三、tail 

一、awk

    2014-07-17 16:56:20 14478 127.0.0.1 E77A964E4722E34A m-write-file 0.017384 0 mx_get_part:0.001,mx_update_part_sha1:0.012,aesenc:0.000,nparts:0.000,sha:0.000,mx_write:0.000,mx_get_file:0.003,assureblks:0.000,rpost:0.000 hash:6563625978a161165d3c9c29a08e1e3500500e54ba,pos:0,fid:52-14055873500,size:4096 res:mx_get_part.52-14055873500.0,mx_get_file.52-14055873500,mx_update_part_sha1.52-14055873500.0.-1,1.mx_write.52-14055873500-0.0.4096

    -w          统计字数

1、wc  命令参数:

    -c            按指定字节显示