0

I have a text file in which I have 3 sections values separated by pipe. My text file:

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.

Now I'm extracting values from this text file using shell script and storing it in a shell variable and now I want to replace the shell variable value to a variable in my HTML file. In this replacement, I want to replace the new lines encountered in the values in text file (stored in shell variable) with <br /> tag so that in my HTML file, output should be in the same format as input given in text file for all the 3 sections.

My shell script to extract and replace the values is :

#! /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

Now, here you can see attendees section, I don't want <br/> tag as there is no new line in 1st section that but I want in agenda section and lscrm section. Note: In above script attendees, agenda and lscrm are variables present in different columns of a table in my HTML file where I want to replace

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

With above attempt <br/> tag is inserted in whole html file and so due this my table in html file is aligned very down in chrome or IE browser.

What changes should be done in above script to get <br> tag only in specicfied user input text area not whole HTML body file?

0

You can make your substitution with awk. Replace:

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

with

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

Do the same for agenda and lscrm. If your are using GNU awk and you don't want the initial and/or ending <br>, you can play with RS:

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.