统计user
2015-06-28 15:12
183 查看
#!/bin/ksh
logpath=/home/felixzh
execpath=/opt/cool/.logs
#redirect stdout/stderr to file
exec 2>&1
exec 1> /home/felixzh/$1
#use function
function readfile
{
filename=$1
y=$2
>$logpath/$y.name
while read line1
do
#use nawk to split line
user=`echo $line1|nawk -F ';' '{print $1}'`
#use >/dev/null or -q ,stop result output to files
grep $user $logpath/$y.name >/dev/null
#grep -q $user $logpath/$y.name
if [ $? != 0 ]
then
echo $user >>$logpath/$y.name
fi
done <$filename
#static lines for file
i=`wc -l $execpath/$filename`
j=`wc -l $logpath/$y.name`
echo "i=$i"
echo "j=$j"
}
function usage
{
echo "./static 2014"
}
if [ $# -lt 1 ]
then
usage
exit
fi
cd $execpath
ls -ltr use* >$logpath/1
year=$1
while read line
do
time=`echo $line |nawk '{print $8}'`
if [ "$time" == "$year" ]
then
name=`echo $line |nawk '{print $9}'`
readfile $name $year
fi
done <$logpath/1
logpath=/home/felixzh
execpath=/opt/cool/.logs
#redirect stdout/stderr to file
exec 2>&1
exec 1> /home/felixzh/$1
#use function
function readfile
{
filename=$1
y=$2
>$logpath/$y.name
while read line1
do
#use nawk to split line
user=`echo $line1|nawk -F ';' '{print $1}'`
#use >/dev/null or -q ,stop result output to files
grep $user $logpath/$y.name >/dev/null
#grep -q $user $logpath/$y.name
if [ $? != 0 ]
then
echo $user >>$logpath/$y.name
fi
done <$filename
#static lines for file
i=`wc -l $execpath/$filename`
j=`wc -l $logpath/$y.name`
echo "i=$i"
echo "j=$j"
}
function usage
{
echo "./static 2014"
}
if [ $# -lt 1 ]
then
usage
exit
fi
cd $execpath
ls -ltr use* >$logpath/1
year=$1
while read line
do
time=`echo $line |nawk '{print $8}'`
if [ "$time" == "$year" ]
then
name=`echo $line |nawk '{print $9}'`
readfile $name $year
fi
done <$logpath/1
相关文章推荐
- SSH配置log4j的方法
- 六祖坛经白话版
- Qt编程之QString 处理换行
- C++经典面试题(八)
- Jetty和tomcat的比较
- ASP.NET MVC显示HTML字符串
- 药师经译文
- OJ期末模考J
- maven项目建立pom.xml报无法解析org.apache.maven.plugins:maven-resources-plugin:2.4.3
- 期末模拟——能存各种类型数据的store类
- 直接复制php的安装目录部署到其他服务器的时候,无法运行
- 佛遗教经译文
- 文殊师利般若经译文
- ubuntu安装xhprof
- C++经典面试题(七)
- Hibernate 入门教程(总结)
- PHP session机制小析
- Extended APDU support
- 佛说长寿灭罪经译文
- Python实现将绝对URL替换成相对URL的方法