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