Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2117978
  • 博文数量: 220
  • 博客积分: 8531
  • 博客等级: 中将
  • 技术积分: 4976
  • 用 户 组: 普通用户
  • 注册时间: 2007-07-18 13:33
文章分类

全部博文(220)

文章存档

2017年(1)

2015年(1)

2014年(5)

2013年(6)

2012年(6)

2011年(30)

2010年(37)

2009年(53)

2008年(41)

2007年(40)

分类: LINUX

2007-08-20 17:39:05

    让我帮着写一个脚本,从一个目录下面所有的子目录(以日期为名)下面所有的日志文件中,搜索字符串'ANI is',然后算出来多少行。

[xiaoqi@localhost Call]$ ls -d 2007-07-3*
2007-07-30 2007-07-31
[xiaoqi@localhost Call]$ ls 2007-07-3*
2007-07-30:
VAGFlowExecutor_2007-07-30_07.log VAGFlowExecutor_2007-07-30_15.log
VAGFlowExecutor_2007-07-30_08.log VAGFlowExecutor_2007-07-30_16.log
VAGFlowExecutor_2007-07-30_09.log VAGFlowExecutor_2007-07-30_17.log
VAGFlowExecutor_2007-07-30_10.log VAGFlowExecutor_2007-07-30_18.log
VAGFlowExecutor_2007-07-30_11.log VAGFlowExecutor_2007-07-30_19.log
VAGFlowExecutor_2007-07-30_12.log VAGFlowExecutor_2007-07-30_20.log
VAGFlowExecutor_2007-07-30_13.log VAGFlowExecutor_2007-07-30_21.log
VAGFlowExecutor_2007-07-30_14.log VAGFlowExecutor_2007-07-30_22.log

2007-07-31:
VAGFlowExecutor_2007-07-31_07.log VAGFlowExecutor_2007-07-31_14.log
VAGFlowExecutor_2007-07-31_08.log VAGFlowExecutor_2007-07-31_15.log
VAGFlowExecutor_2007-07-31_09.log VAGFlowExecutor_2007-07-31_16.log
VAGFlowExecutor_2007-07-31_10.log VAGFlowExecutor_2007-07-31_17.log
VAGFlowExecutor_2007-07-31_11.log VAGFlowExecutor_2007-07-31_19.log
VAGFlowExecutor_2007-07-31_12.log VAGFlowExecutor_2007-07-31_20.log
VAGFlowExecutor_2007-07-31_13.log


    因为子目录和里面的文件都有一定规则,所以写起来比较简单。用两个for就搞定了。

[xiaoqi@localhost Call]$ cat list.sh
#!/bin/bash
for i in ./20*
do
        for j in $i/*
        do
        echo "$j"" "`grep -Ra 'ANI is' $j|wc -l`
        done
done

for i in ./20*
do
echo "---------------------------------"
echo $i" "`grep -Ra 'ANI is' $i|wc -l`
echo "---------------------------------"
done

echo " "
echo "---------------------------------"
echo "just a moment ; the total is ...."
echo "the total is "`grep -Ra 'ANI is' *|wc -l`
echo "---------------------------------"


    执行效果如下:

[xiaoqi@localhost Call]$ ./list.sh

./2007-07-30
./2007-07-30/VAGFlowExecutor_2007-07-30_07.log 3
./2007-07-30/VAGFlowExecutor_2007-07-30_08.log 5
./2007-07-30/VAGFlowExecutor_2007-07-30_09.log 31
./2007-07-30/VAGFlowExecutor_2007-07-30_10.log 24
./2007-07-31
./2007-07-31/VAGFlowExecutor_2007-07-31_07.log 0
./2007-07-31/VAGFlowExecutor_2007-07-31_08.log 6
./2007-07-31/VAGFlowExecutor_2007-07-31_09.log 7
./2007-07-31/VAGFlowExecutor_2007-07-31_10.log 15
---------------------------------
./2007-07-30         199
---------------------------------
---------------------------------
./2007-07-31         111
---------------------------------

---------------------------------
just a moment ; the total is ....
the total is 23418
---------------------------------

阅读(2128) | 评论(0) | 转发(1) |
给主人留下些什么吧!~~