需求:
现在遇到一个问题,文件内容如下;
Sep 06 01:12:20.079649 pid 9275 (pool default)
script_filename = /export/home/index.php
Sep 06 01:12:21.384616 pid 9441 (pool default)
script_filename = /export/home/more.php
Sep 06 01:12:28.822470 pid 9419 (pool default)
Sep 06 01:12:35.870249 pid 9124 (pool default)
script_filename = /export/home/ps_more.php
Sep 06 01:12:40.830110 pid 9341 (pool default)
script_filename = /export/home/pb_index.php
Sep 06 01:12:28.822470 pid 9419 (pool default)
Sep 06 01:12:35.870249 pid 9124 (pool default)
Sep 06 01:12:28.822470 pid 9419 (pool default)
Sep 06 01:12:45.922982 pid 9023 (pool default)
script_filename = /export/home/auto/index.php
现在需要将重复的Sep开头的行去除.结果应该如下:
Sep 06 01:12:20.079649 pid 9275 (pool default)
script_filename = /export/home/index.php
Sep 06 01:12:21.384616 pid 9441 (pool default)
script_filename = /export/home/more.php
Sep 06 01:12:35.870249 pid 9124 (pool default)
script_filename = /export/home/ps_more.php
Sep 06 01:12:45.922982 pid 9023 (pool default)
script_filename = /export/home/auto/index.php
就是凡是连续两个或者多个Sep开头的行下面没有script_filename的都删除.结果就变成一行Sep时间行,下面就应该是script_filename行.
解答:
awk 'a!=$1{a=$1;print}' yourfile
阅读(4136) | 评论(0) | 转发(0) |