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

  • 时间:
  • 浏览:3

    -v            输突然总出 示文件的文件名

    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.8388508

三、tail 

2、统计 acc.log 有几个行

    -l            统计行数

    404

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

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.da39a3ee5e6b4b0d3255bfef95501890afd50709,1.ax_put.da39a3ee5e6b4b0d3255bfef95501890afd50709.0.0,ax_get_blk.da39a3ee5e6b4b0d3255bfef95501890afd50709,mx_get_file.19-1405586413

2、head 使用

    -w          统计字数

    -q            隐藏文件名

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

一、awk

    50 acc.log

    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:6563625978a161165d3c9c29a08e1e35050e54ba,pos:0,fid:52-1405587350,size:4096 res:mx_get_part.52-1405587350.0,mx_get_file.52-1405587350,mx_update_part_sha1.52-1405587350.0.-1,1.mx_write.52-1405587350-0.0.4096

1、head 命令参数

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:972a2132d506708d586540b4822681ec43188148,pos:0,fid:52-1405587350,size:4096 res:mx_get_part.52-1405587350.0,mx_get_file.52-1405587350,mx_update_part_sha1.52-1405587350.0.-1,1.mx_write.52-1405587350-0.0.4096

    # 获取最后 3 条日志

二、head

    -c           统计字节数

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-1405587350,size:4096 res:mx_get_part.52-1405587350.0,mx_get_file.52-1405587350,mx_update_part_sha1.52-1405587350.0.4096,1.mx_write.52-1405587350-0.0.4096

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

四、wc 

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

    -n            指定获取几个行

1、wc  命令参数:

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

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

    # 获取前 3 条日志

    -c            按指定字节显示