免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2963 | 回复: 4
打印 上一主题 下一主题

[文本处理] 请教高手,怎么实现这个 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2013-11-04 16:13 |只看该作者 |倒序浏览
本帖最后由 jlds123 于 2013-11-04 16:17 编辑

首先有一个配置文件A如下:

  1. LogFile="/logs/localhost_20130514.log"
  2. # Enter the log file type you want to analyze.
  3. # Possible values:
  4. #  W - For a web log file
  5. #  S - For a streaming log file
  6. #  M - For a mail log file
  7. #  F - For a ftp log file
  8. # Example: W
复制代码
参数文件B如下:
  1. localhost_20130616.log
  2. localhost_20130617.log
  3. localhost_20130618.log
  4. localhost_20130619.log
  5. localhost_20130620.log
  6. localhost_20130621.log
  7. localhost_20130622.log
  8. localhost_20130623.log
  9. localhost_20130624.log
  10. localhost_20130625.log
  11. localhost_20130626.log
  12. localhost_20130627.log
  13. localhost_20130628.log
  14. localhost_20130629.log
  15. localhost_20130630.log
  16. localhost_20130701.log
  17. localhost_20130702.log
  18. localhost_20130703.log
  19. localhost_20130704.log
  20. localhost_20130705.log
  21. localhost_20130706.log
复制代码
执行
  1. perl  /usr/local/awstats/wwwroot/cgi-bin/awstats.pl  -update -config=localhost
复制代码
输出如下:
  1. Jumped lines in file: 677730
  2. Found 677730 already parsed records.
  3. Parsed lines in file: 0
  4. Found 0 dropped records,
  5. Found 0 comments,
  6. Found 0 blank records,
  7. Found 0 corrupted records,
  8. Found 0 old records,
  9. Found 0 new qualified records.
复制代码
想实现效果:
每执行一次上面perl命令,执行完成后,配置文件A中的localhost_20130514.log循环替换成参数文件B中的每一行,然后执行perl命令

实际上B文件可能很多行,所以需要写个脚本

论坛徽章:
93
2015年辞旧岁徽章
日期:2019-10-10 10:51:15CU大牛徽章
日期:2014-02-21 14:21:56CU十二周年纪念徽章
日期:2020-10-15 16:55:55CU大牛徽章
日期:2014-02-21 14:22:07羊年新春福章
日期:2019-10-10 10:51:39CU大牛徽章
日期:2019-10-10 10:55:38季节之章:春
日期:2020-10-15 16:57:40ChinaUnix元老
日期:2019-10-10 10:54:42季节之章:冬
日期:2019-10-10 10:57:17CU大牛徽章
日期:2014-02-21 14:22:52CU大牛徽章
日期:2014-03-13 10:40:30CU大牛徽章
日期:2014-02-21 14:23:15
2 [报告]
发表于 2013-11-04 16:52 |只看该作者
  1. while read file; do echo "LogFile=\"/logs/$file\"" > A; perl xxxx; done < B
复制代码

论坛徽章:
39
辰龙
日期:2013-08-21 15:45:192015亚冠之广州富力
日期:2015-05-12 16:34:52亥猪
日期:2015-03-03 17:22:00申猴
日期:2015-03-03 17:21:37未羊
日期:2014-10-10 13:45:41戌狗
日期:2014-06-17 09:53:29巨蟹座
日期:2014-06-12 23:17:17双鱼座
日期:2014-06-10 12:42:44寅虎
日期:2014-06-09 12:52:172015亚冠之卡尔希纳萨夫
日期:2015-05-24 15:24:35黄金圣斗士
日期:2015-12-02 17:25:0815-16赛季CBA联赛之吉林
日期:2017-06-24 16:43:52
3 [报告]
发表于 2013-11-04 22:21 |只看该作者
本帖最后由 关阴月飞 于 2013-11-04 22:22 编辑

回复 1# jlds123


    目测一下:
  1. #!/bin/bash
  2. while read line
  3. do
  4. sed -i  "1c\LogFile=\"$line\"" A
  5. perl /usr/local/awstats/wwwroot/cgi-bin/awstats.pl  -update -config=localhost
  6. done < B
复制代码

论坛徽章:
15
2015年辞旧岁徽章
日期:2015-03-03 16:54:15双鱼座
日期:2015-01-15 17:29:44午马
日期:2015-01-06 17:06:51子鼠
日期:2014-11-24 10:11:13寅虎
日期:2014-08-18 07:10:55酉鸡
日期:2014-04-02 12:24:51双子座
日期:2014-04-02 12:19:44天秤座
日期:2014-03-17 11:43:36亥猪
日期:2014-03-13 08:13:51未羊
日期:2014-03-11 12:42:03白羊座
日期:2013-11-20 10:15:18CU大牛徽章
日期:2013-04-17 11:48:45
4 [报告]
发表于 2013-11-06 11:16 |只看该作者
本帖最后由 rdcwayx 于 2013-11-06 13:18 编辑

印象里,这个命令支持-LogFile 参数的。
  1. while read logfile
  2. do
  3.   perl  /usr/local/awstats/wwwroot/cgi-bin/awstats.pl  -update -config=localhost -LogFile $logfile
  4. done < fileB
复制代码
https://help.ubuntu.com/community/AWStats
http://awstats.sourceforge.net

论坛徽章:
0
5 [报告]
发表于 2013-11-06 15:47 |只看该作者
rdcwayx 发表于 2013-11-06 11:16
印象里,这个命令支持-LogFile 参数的。https://help.ubuntu.com/community/AWStats
http://awstats.sourc ...


感谢楼上各位
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP