从具有|的文本文件中提取值 使用awk命令将管道作为文本文件中的定界符,并使用sed将<br>标记替换为新行?

阿披耶·阿南德

我有一个文本文件,其中有3个部分值,它们之间用管道分隔。我的文字档:

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

MCRM:Zahoor

TLGAPI:Bhargav

MOM:Manika|
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.

现在,我使用Shell脚本从此文本文件中提取值并将其存储在Shell变量中,现在我想将Shell变量值替换为HTML文件中的变量。在此替换中,我要替换文本文件(存储在shell变量中)中的值中遇到的新行,<br /> tag以便在我的HTML文件中,对于所有3个部分,输出应与文本文件中输入的格式相同。

我的用于提取和替换值的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"
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

现在,您可以在此处看到与会者部分,我不想要,<br/> tag因为在第一部分中没有新行,但是我想要在议程部分和lscrm部分中。注意:在上述脚本与会者中,议程和lscrm是存在于我要替换的HTML文件中表的不同列中的变量

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

通过以上尝试,<br/>标记将插入整个html文件中,因此,由于此原因,html文件中的表格在chrome或IE浏览器中向下对齐。

为了<br>仅在特定的用户输入文本区域而不是整个HTML正文文件中获取标签,应在上述脚本中进行哪些更改

希恩

您可以使用进行替换awk代替:

attendees=$( awk 'BEGIN { RS = "|" } NR == 1 { print }' $file )

attendees=$( awk 'BEGIN { RS = "|" } NR == 1 { print gensub("\n", "<br />", "g") }' $file )

agenda执行相同的操作lscrm如果您使用的是GNU awk,并且您不希望使用“ initial”和/或“ ending” <br>,则可以使用RS:

attendees=$( awk 'BEGIN { RS = "\n*\\|\n*" } ...' $file )

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

Related 相关文章

热门标签

归档