如何用我的 awk 脚本填充 html 数组?

How Can I fill an html array with my awk script?

对于 bash/html 中的 CGI,我尝试在 html 数组中显示许多 CSV 文件中的一些信息。所以我使用这个脚本:

#!/bin/bash

echo "Content-type: text/html"
echo ""
echo '
<html>
        <head>
                <meta http-equiv="Content-Type" content="test/html"; charset=UTF-8">
                <title> CLF MONITORING </title>
                <h1> FRAME monitoring <font size=3> <a href="Index.sh">[ Index ]</a> </font> </h1>
                <hr size="4" color="blue">

        <style>
                         body{
                          background-color: #eff1f0;
                         }
        </style>

        </head>
<body>'

read a
test=$( echo $a | cut -d'=' -f2)

echo '<PRE>'

echo "FRAME : $test "
echo "------------------"

echo ""


echo "<table>"
echo "<tr>"
echo "<td>"
echo "<PRE>"
for fn in /var/www/cgi-bin/LPAR_MAP/*; do 
    awk -F',|;' 'NR==1 { split(FILENAME ,a,"[-.]");
       print "DATE ========================== : " a[4] }
       /'$test'/ { 
           print ""
           print "LPARS :" 
           print "RAM : " 
           print "CPU 1 : " 
           print "CPU 2 : " 
           print "" 
           print ""}' $fn; 
done
echo "</PRE>"
echo "</td>"
echo "</tr>"
echo "</table>"
echo '</PRE>'
echo '</body>
</html>'

输出为:

FRAME : MIAIBYC00 
------------------

DATE ========================== : 20180705

LPARS :HSCL9010 This operation is only allowed when the managed system is in the Standby or Operating state.
RAM : 
CPU 1 : 
CPU 2 : 


DATE ========================== : 20180122

LPARS :miaibv228
RAM : 8
CPU 1 : 2.0
CPU 2 : 4



LPARS :miaibv158
RAM : 5
CPU 1 : 0.1
CPU 2 : 1



LPARS :miaibv157
RAM : 6
CPU 1 : 0.2
CPU 2 : 1



LPARS :OSvalidation
RAM : 0.25
CPU 1 : 0.2
CPU 2 : 1



LPARS :miaibv104
RAM : 64
CPU 1 : 3.0
CPU 2 : 7

... 

DATE ========================== : 20180124

LPARS :miaibv228
RAM : 8
CPU 1 : 2.0
CPU 2 : 4



LPARS :miaibv158
RAM : 5
CPU 1 : 0.1
CPU 2 : 1



LPARS :miaibv157
RAM : 6
CPU 1 : 0.2
CPU 2 : 1



LPARS :OSvalidation
RAM : 0.25
CPU 1 : 0.2
CPU 2 : 1

但我想创建很多列,如下所示:

想法是:为一个“日期 ==========”创建一列,下面是他的信息,但是列数。

例如:

Date ========= XXXXX    Date ============ XXXXX    Date ============== XXXXXXX

LPARS :miaibv228        LPARS : XXXXXX             LPARS : XXXXX
RAM : 8                 RAM : XXXXXX               RAM : XXXXXX
CPU 1 : 2.0             CPU 1 : XXXXX              CPU 1 : XXXXX
CPU 2 : 4               CPU 2 :  XXXXX             CPU 2 : XXXXXX

对于这个例子,我只有 3 个“日期”和一些信息。但实际上,我有更多的信息。

你有什么想法吗?

我认为您只需将 <td><pre> 标签移动到循环内即可:

. . .
for fn in /var/www/cgi-bin/LPAR_MAP/*; do 
    echo "<td>"
    echo "<PRE>"
    awk -F',|;' 'NR==1 { split(FILENAME ,a,"[-.]");
       print "DATE ========================== : " a[4] }
       /'$test'/ { 
           print ""
           print "LPARS :" 
           print "RAM : " 
           print "CPU 1 : " 
           print "CPU 2 : " 
           print "" 
           print ""}' $fn; 
    echo "</PRE>"
    echo "</td>"
done
. . .