shell脚本-凯发app官方网站

凯发app官方网站-凯发k8官网下载客户端中心 | | 凯发app官方网站-凯发k8官网下载客户端中心
  • 博客访问: 2018314
  • 博文数量: 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
---------------------------------

阅读(1964) | 评论(0) | 转发(1) |
给主人留下些什么吧!~~
")); function link(t){ var href= $(t).attr('href'); href ="?url=" encodeuricomponent(location.href); $(t).attr('href',href); //setcookie("returnouturl", location.href, 60, "/"); }
网站地图