用HTML 文件中的标记替换文本文件中的新行

用HTML 文件中的标记替换文本文件中的新行

实际上,我正在为我办公室的基础设施团队制作一个自制工具“MOM”。我的工具有一个文本文件“妈妈.txt”和一个名为“的 HTML 文件妈妈.html" 。我有一个 shell 脚本,它获取“mom.html”的副本并将其命名为momcpy.html 我发送这个momcpy.html通过邮件将会议报告提交给我的团队 DL。我在此处附加了我的工具和不同文件的图像:

我用于将“会议纪要”发送到团队邮件的工具:

在此输入图像描述

在此输入图像描述

现在在最后,我有提交按钮,当我点击它时,它会将 html 报告发送到邮件,即文件“momcpy.html

我的 ”妈妈.txt“ 文件如下:

    Saibal,Navnath,Taral,Sagar,Ankit,Prasham,Manika,Arvind,Gaurav,Abhijeet,Rohit,Madhu,Ganesh,Zahoor|
LSCRM:Abhijeet

MCRM:Arvind

TLGAPI:Bhargav

MOM:Manikaa|
Prod :
No major activity were scheduled and no issues were reported throughout the week.
Last weekend on Sunday, we performed Full bounce. We are doing so to allow any USDOTT transaction during this window while they do code-fix (they need CRM available at all times).
Coming weekend, we have ordering client Ef deployment and CK External BLM Phase 2 activity scheduled on both APH and STL.

Non-Prod:
Over the week, we released 1710 CT11 K2view to build: 220 and Env TRN3 to 1707 Build:300.
|
PROD:
We have 2Q OS Patching on DR and Production.
There was an issue of Sync reject long response time reported for NBI Market . It was run in debug mode to investigate further.
Coming weekend, the scheduled DR switchover activity got cancelled.
Coming weekend we have Weblogic phase 2 migration activity as well as weekly config build.

Non Prod:
We have 2Q OS Patching activity on QA and TRN envs.|
PROD:

WTC cleanup activity completed successfully.
No major issues reported.

NON PROD

Configuration changes on DB end for 1710 envs done.
There was an issue due to heap size on few jvms.Clients got impacted. We tried to do Rolling bounce but issue still persist. After half an hour issue got resolved itself.
|
No updates|
break|

因此,单击用户在与会者、议程、LSCRMUpdates、MCRM 更新和 Tlgapi 更新以及其他更新中输入的详细信息时,将保存在文本文件中“妈妈.txt”上面给出。

现在你可以看到我已经使用了管道 |作为分隔符来提取用户作为输入给出的不同部分数据。

现在我作为邮件发送的 momcpy.html 文件报告其代码:

<!--
To change this template, choose Tools | Templates
and open the template in the editor.
-->
<!DOCTYPE html>
<html>
    <head>
        <title>CRM Infra MOM Weekly Reports</title>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
         <link href='http://fonts.googleapis.com/css?family=Exo:700' rel='stylesheet' type='text/css'>
         <link rel="stylesheet" type="text/css" href="mom.css">
         <script src="mom.js"></script>
    </head>
    <body onLoad="xx()">
      <p class="exe1"><div id="content-wrap">
           <p class="exe1"><h1 valign="top">CRM Infra Weekly Report</h1></p>
            <br/>
          <p class="exe1"><table  align="center"  border="6" cellpadding="10" cellspacing="10">
                <tr>
                    <th height="15" style="font-size:20px;line-height:10px;" bgcolor="#808080"><label for="attendees">Attendees</label></th>
                </tr>
                <tr>
                    <td><textarea rows="10" cols="140">attendees</textarea></td>
                </tr>
                <tr>
                        <th height="12" bgcolor="#808080">Agenda:</th>
                </tr>
                <tr>
                    <td height="70" bgcolor="#FFFFFF">agenda.</td>
                </tr>
                 <tr>
                        <th height="12"  bgcolor="#808080"><label for="lscrm">LSCRM:</label></th>
                </tr>
                <tr>
                    <td height="60" bgcolor="#FFFFFF">lscrm</td>
                </tr>
                <tr>
                        <th height="12" bgcolor="#808080"><label for="mcrm">MCRM:</label></th>
                </tr>
                <tr>
                    <td height="60" bgcolor="#FFFFFF">mcrm</td>
                </tr>
                  <tr>
                        <th height="12" bgcolor="#808080"><label for="mcrm">TLGAPI:</label></th>
                </tr>
                <tr>
                    <td height="60" bgcolor="#FFFFFF">tlgapi</td>
                </tr>
                  <tr>
                        <th height="12" bgcolor="#808080"><label for="other">Other Updates:</label></th>
                </tr>
                <tr>
                    <td height="60" bgcolor="#FFFFFF">other</td>
                </tr>

            </table></p>
        </div></p>
    </body>
</html>

在这个文件中,我有一个表,其行和列与我的工具表结构相同。这里,我在不同的行中有不同的变量,如 lscrm、mcrm、议程、与会者、tlgapi,并且我使用管道作为分隔符,将这些变量替换为 mom.txt 文件中存在的值(由用户作为输入给出的值)。

我通过使用 shell 脚本来做到这一点:

#! /bin/bash -x
file='/home/websphe/tomcat/webapps/MOM/mom.txt'
file1='/home/websphe/tomcat/webapps/MOM/web/mom.html'
common_path='/home/websphe/tomcat/webapps/MOM/web/'
if test -s $file
   then
cp $file1 $common_path/momcpy.html
attendees=$( awk 'BEGIN { RS = "|" } NR == 1 { print }' $file )
echo "$attendees"
agenda=$( awk 'BEGIN { RS = "|" } NR == 2 { print }' $file )
echo "$agenda"
lscrm=$( awk 'BEGIN { RS = "|" } NR == 3 { print }' $file )
echo "$lscrm"
mcrm=$( awk 'BEGIN { RS = "|" } NR == 4 { print }' $file )
echo "$mcrm"
tlgapi=$( awk 'BEGIN { RS = "|" } NR == 5 { print }' $file )
echo  "$tlgapi"
other=$( awk 'BEGIN { RS = "|" } NR == 6 { print }' $file )
echo "$other"
trial=$( awk 'BEGIN { RS = "|" } NR == 7 { print }' $file )
perl -p -i -e "s#attendees#$attendees#g" $common_path/momcpy.html
perl -p -i -e "s#agenda#$agenda#g" $common_path/momcpy.html
perl -p -i -e "s#lscrm#$lscrm#g" $common_path/momcpy.html
perl -p -i -e "s#mcrm#$mcrm#g" $common_path/momcpy.html
perl -p -i -e "s#tlgapi#$tlgapi#g" $common_path/momcpy.html
perl -p -i -e "s#other#$other#g" $common_path/momcpy.html
perl -p -i -e "s#trial#$trial#g" $common_path/momcpy.html
     echo "`/bin/sh /home/websphe/tomcat/webapps/MOM/web/./mail.sh`"

             #rm $file
            # rm $common_path/momcpy.html
  else
    echo "Sorry no email sent :("
fi

我现在的问题陈述:

我想以与“mom.txt”文件中不同部分相同的方式获取详细信息LSCRM 更新、MCRM 更新等等(或者你可以说用户给出的输入)。由于我将这些文本文件的输入写入 HTML 文件,因此我需要
使用 HTML 中的标签替换新行出现的位置上面提到的shell脚本 笔记: 我只想<br> tag在文本输入部分中添加,而不是在 html 文件的每个部分中添加。否则它会变得非常向下对齐。

目前我在我的脚本中使用了它:

perl -p -i -e "s#attendees#$attendees#g" $common_path/momcpy.html
perl -p -i -e "s#agenda#$agenda#g" $common_path/momcpy.html | sed -i'' 's|\n|<br>|' $common_path/momcpy.html
perl -p -i -e "s#lscrm#$lscrm#g" $common_path/momcpy.html | sed -i'' 's|\n|<br>|' $common_path/momcpy.html
perl -p -i -e "s#mcrm#$mcrm#g" $common_path/momcpy.html | sed -i'' 's|\n|<br>|' $common_path/momcpy.html
perl -p -i -e "s#tlgapi#$tlgapi#g" $common_path/momcpy.html | sed -i'' 's|\n|<br>|' $common_path/momcpy.html
perl -p -i -e "s#other#$other#g" $common_path/momcpy.html | sed -i'' 's|\n|<br>|' $common_path/momcpy.html
perl -p -i -e "s#trial#$trial#g" $common_path/momcpy.html | sed -i'' 's|$|<br>|' $common_path/momcpy.html

但它<br> tags在我的 HTML 文件中到处添加,并且表格在浏览器 Chrome 或 IE 中对齐得非常靠下。

答案1

很简单,只需删除g命令中的标志即可,因为它会导致替换所有事件。

相关内容