让我帮着写一个脚本,从一个目录下面所有的子目录(以日期为名)下面所有的日志文件中,搜索字符串'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 ---------------------------------
|
阅读(2106) | 评论(0) | 转发(1) |