免费注册 查看新帖 |

Chinaunix

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

[文本处理] [shell] 每次读取三行内容并插入一个表格中 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2015-07-23 16:09 |只看该作者 |倒序浏览
我设置了一个变量ImgPath=$(find $PWD -depth -maxdepth 3 -name "*Cpu_U*.gif" -o -name "*Cpu_S*.gif" -o -name "*Memory_Free.gif" | sort -n)

内容为:

/u01/test_dir/OSwatch_Result_Hotspot_1432794030/2015-06-09~13-22-47_OSwatcher_Test_Compress_file_Multi_Processes/OSWg_OS_Cpu_User.gif
/u01/test_dir/OSwatch_Result_Hotspot_1432794030/2015-06-09~13-22-47_OSwatcher_Test_Compress_file_Multi_Processes/OSWg_OS_Memory_Free.gif
/u01/test_dir/OSwatch_Result_Hotspot_1432794030/2015-06-09~13-22-47_OSwatcher_Test_Compress_file_Multi_Threads/OSWg_OS_Cpu_System.gif
/u01/test_dir/OSwatch_Result_Hotspot_1432794030/2015-06-09~13-22-47_OSwatcher_Test_Compress_file_Multi_Threads/OSWg_OS_Cpu_User.gif
......

想每次读取三行内容并插入一个表格中

我写的脚本:

#!/bin/sh

  ImgPath=$(find $PWD -depth -maxdepth 3 -name "*Cpu_U*.gif" -o -name "*Cpu_S*.gif" -o -name "*Memory_Free.gif" | sort -n)
  
  cat <<EOF >report.html
  <html>
  <table width="1000" border="1" align="center" cellpadding="2" cellspacing="0" bordercolor="#333333">
  <tr><td width="15%" bgcolor="#00FFFF"><span class="STYLE5">TestCase</span></td>
  <td width="15%" bgcolor="#00FFFF"><span class="STYLE5">Grinder Component</span></td>
  <td width="15%" bgcolor="#00FFFF"><span class="STYLE5">Grinder Component</span></td>
  <td width="10%" bgcolor="#00FFFF"><span class="STYLE5">value</span></td>
  <td width="15%" bgcolor="#00FFFF"><span class="STYLE5">JVM Arguments </span></td>
  <td width="25%" bgcolor="#00FFFF"><span class="STYLE5">value</span></td>
  <td width="10%" bgcolor="#00FFFF"><span class="STYLE5">OS Kernal </span></td>
  <td bgcolor="#00FFFF"><span class="STYLE5">Value</span></td></tr>

  <tr><td rowspan="5"><span class="STYLE9"></span></td>
  <td><span class="STYLE10">runMode</span></td>
  <td><span class="STYLE10">continuous</span></td>
  <td rowspan="5"><span class="STYLE10">Jvm.argument</span></td>
  <td rowspan="2"><span class="STYLE10">Hotspot:</span></td>
  <td><span class="STYLE10">runMode</span></td>
  <td><span class="STYLE10">1</span></td></tr>

  <tr><td><span class="STYLE10">durationHour</span></td>
  <td><span class="STYLE10">1</span></td>"
  <td><span class="STYLE10">durationHour</span></td>
  <td><span class="STYLE10">1</span></td></tr>

  <tr><td><span class="STYLE10">processors</span></td>
  <td><span class="STYLE10">1</span></td>
  <td rowspan="3"><span class="STYLE10">JRockit:</span></td>
  <td><span class="STYLE10">processors</span></td>
  <td><span class="STYLE10">10</span></td></tr>

  <tr><td><span class="STYLE10">threads</span></td>
  <td><span class="STYLE10">10</span></td>
  <td><span class="STYLE10">threads</span></td>
  <td><span class="STYLE10">1000</span></td></tr>

  <tr><td><span class="STYLE10">arrayLength</span></td>
  <td><span class="STYLE10">1000</span></td>
  <td><span class="STYLE10">arrayLength</span></td>
  <td><span class="STYLE9"></span></td></tr></table>

EOF1

  while read line; do
        case $((i++ % 3)) in
            echo -n "a=$line ";
  done<report.html

  cat <<EOF2 >> report.html

  <table width="1000" border="1" align="center" cellpadding="2" cellspacing="0" bordercolor="#333333">

  <tr><td rowspan="5"><span class="STYLE9"><a href=\"$img\"><img src="$ImgPath" /a></span></td></tr></table>

  </html>
EOF2

但是实现不了, 请帮忙看看 谢谢



论坛徽章:
54
2015亚冠之德黑兰石油
日期:2015-07-07 13:00:1615-16赛季CBA联赛之深圳
日期:2016-03-31 09:03:5415-16赛季CBA联赛之辽宁
日期:2016-05-09 20:38:15程序设计版块每日发帖之星
日期:2016-05-12 06:20:0015-16赛季CBA联赛之四川
日期:2016-05-13 15:19:4715-16赛季CBA联赛之福建
日期:2016-05-15 20:24:34每日论坛发贴之星
日期:2016-05-16 06:20:0015-16赛季CBA联赛之吉林
日期:2016-05-26 11:49:4715-16赛季CBA联赛之广东
日期:2016-05-26 13:49:18极客徽章
日期:2016-12-07 14:05:2315-16赛季CBA联赛之广夏
日期:2016-12-20 17:33:532017金鸡报晓
日期:2017-01-10 15:19:56
2 [报告]
发表于 2015-07-23 16:20 |只看该作者
  1. while read line; do
  2.       case $((i++ % 3)) in
  3.           3) echo -n "$s";;
  4.       esac
  5. done<report.html
复制代码
你这个地方格式有问题吧.

论坛徽章:
0
3 [报告]
发表于 2015-07-23 16:33 |只看该作者
谢谢, 我测试了还是不成,每行插入的还是全部的内容,


#!/bin/sh

  ImgPath=$(find $PWD -depth -maxdepth 3 -name "*Cpu_U*.gif" -o -name "*Cpu_S*.gif" -o -name "*Memory_Free.gif" | sort -n)
  
  cat <<EOF >report.html
  <html>
  <table width="1000" border="1" align="center" cellpadding="2" cellspacing="0" bordercolor="#333333">
  <tr><td width="15%" bgcolor="#00FFFF"><span class="STYLE5">TestCase</span></td>
  <td width="15%" bgcolor="#00FFFF"><span class="STYLE5">Grinder Component</span></td>
  <td width="15%" bgcolor="#00FFFF"><span class="STYLE5">Grinder Component</span></td>
  <td width="10%" bgcolor="#00FFFF"><span class="STYLE5">value</span></td>
  <td width="15%" bgcolor="#00FFFF"><span class="STYLE5">JVM Arguments </span></td>
  <td width="25%" bgcolor="#00FFFF"><span class="STYLE5">value</span></td>
  <td width="10%" bgcolor="#00FFFF"><span class="STYLE5">OS Kernal </span></td>
  <td bgcolor="#00FFFF"><span class="STYLE5">Value</span></td></tr>

  <tr><td rowspan="5"><span class="STYLE9"></span></td>
  <td><span class="STYLE10">runMode</span></td>
  <td><span class="STYLE10">continuous</span></td>
  <td rowspan="5"><span class="STYLE10">Jvm.argument</span></td>
  <td rowspan="2"><span class="STYLE10">Hotspot:</span></td>
  <td><span class="STYLE10">runMode</span></td>
  <td><span class="STYLE10">1</span></td></tr>

  <tr><td><span class="STYLE10">durationHour</span></td>
  <td><span class="STYLE10">1</span></td>"
  <td><span class="STYLE10">durationHour</span></td>
  <td><span class="STYLE10">1</span></td></tr>

  <tr><td><span class="STYLE10">processors</span></td>
  <td><span class="STYLE10">1</span></td>
  <td rowspan="3"><span class="STYLE10">JRockit:</span></td>
  <td><span class="STYLE10">processors</span></td>
  <td><span class="STYLE10">10</span></td></tr>

  <tr><td><span class="STYLE10">threads</span></td>
  <td><span class="STYLE10">10</span></td>
  <td><span class="STYLE10">threads</span></td>
  <td><span class="STYLE10">1000</span></td></tr>

  <tr><td><span class="STYLE10">arrayLength</span></td>
  <td><span class="STYLE10">1000</span></td>
  <td><span class="STYLE10">arrayLength</span></td>
  <td><span class="STYLE9"></span></td></tr></table>

EOF1

while read line; do
      case $((i++ % 3)) in
          3) echo -n "$s";;
      esac
done<report.html

  cat <<EOF2 >> report.html

  <table width="1000" border="1" align="center" cellpadding="2" cellspacing="0" bordercolor="#333333">
  <tr><td rowspan="5"><span class="STYLE9"><a href=\"$img\"><img src="$ImgPath" /a></span></td></tr></table>
  <table width="1000" border="1" align="center" cellpadding="2" cellspacing="0" bordercolor="#333333">
  <tr><td rowspan="5"><span class="STYLE9"><a href=\"$img\"><img src="$ImgPath" /a></span></td></tr></table>
   <table width="1000" border="1" align="center" cellpadding="2" cellspacing="0" bordercolor="#333333">
  <tr><td rowspan="5"><span class="STYLE9"><a href=\"$img\"><img src="$ImgPath" /a></span></td></tr></table>
  <table width="1000" border="1" align="center" cellpadding="2" cellspacing="0" bordercolor="#333333">
  <tr><td rowspan="5"><span class="STYLE9"><a href=\"$img\"><img src="$ImgPath" /a></span></td></tr></table>
  <table width="1000" border="1" align="center" cellpadding="2" cellspacing="0" bordercolor="#333333">
  <tr><td rowspan="5"><span class="STYLE9"><a href=\"$img\"><img src="$ImgPath" /a></span></td></tr></table>
  <table width="1000" border="1" align="center" cellpadding="2" cellspacing="0" bordercolor="#333333">
  <tr><td rowspan="5"><span class="STYLE9"><a href=\"$img\"><img src="$ImgPath" /a></span></td></tr></table>

  </html>
EOF2

论坛徽章:
54
2015亚冠之德黑兰石油
日期:2015-07-07 13:00:1615-16赛季CBA联赛之深圳
日期:2016-03-31 09:03:5415-16赛季CBA联赛之辽宁
日期:2016-05-09 20:38:15程序设计版块每日发帖之星
日期:2016-05-12 06:20:0015-16赛季CBA联赛之四川
日期:2016-05-13 15:19:4715-16赛季CBA联赛之福建
日期:2016-05-15 20:24:34每日论坛发贴之星
日期:2016-05-16 06:20:0015-16赛季CBA联赛之吉林
日期:2016-05-26 11:49:4715-16赛季CBA联赛之广东
日期:2016-05-26 13:49:18极客徽章
日期:2016-12-07 14:05:2315-16赛季CBA联赛之广夏
日期:2016-12-20 17:33:532017金鸡报晓
日期:2017-01-10 15:19:56
4 [报告]
发表于 2015-07-23 16:51 |只看该作者
回复 3# cgiyan


    忘了说, 你的 EOF1 也只有一个,  上面的 是 EOF

论坛徽章:
0
5 [报告]
发表于 2015-07-23 16:53 |只看该作者
是的,EOF1已经改了,多谢了

论坛徽章:
0
6 [报告]
发表于 2015-07-24 09:51 |只看该作者
哪位高手给帮忙看看,谢谢
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP