如何在我的awk脚本中将变量放在正则表达式中?

时间:2019-07-17 14:24:33

标签: regex linux bash awk

对于bash / html中的CGI,我有此脚本,可以让我分析许多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 ""

#cat /var/www/cgi-bin/LPAR_MAP/*.csv | grep $test  |awk -F',|;' '{print $2","$5","$6","$7}' | awk -F',|;' '{ 

#print "LPARS :" $1;
#print "RAM : " $2
#print "CPU 1 : " $3

for fn in /var/www/cgi-bin/LPAR_MAP/*; do awk -F',|;' 'NR==1 { print 'FILENAME ========================== : ' FILENAME }
/foo/ { 
print ""
print "LPARS :" $2
print "RAM : " $5
print "CPU 1 : " $6
print "CPU 2 : " $7
print "" 
print ""}' $fn; done

echo '</PRE>'

echo '</body>
</html>'

要正确运行脚本,我想用变量$ test替换“ foo”。

所以我尝试像这样放置变量$ test:

for fn in /var/www/cgi-bin/LPAR_MAP/*; do awk -F',|;' 'NR==1 { print 'FILENAME ========================== : ' FILENAME }
/$test/

或者这样:

for fn in /var/www/cgi-bin/LPAR_MAP/*; do awk -F',|;' 'NR==1 { print 'FILENAME ========================== : ' FILENAME }
/${test}/

但这不起作用...你能告诉我怎么做吗?

谢谢! :)

0 个答案:

没有答案