|を使用してテキストファイルから値を抽出し、awkコマンドを使用してテキストファイルの区切り文字にパイプし、 sedを使用して新しい行をマーカーに置き換えますか?

|を使用してテキストファイルから値を抽出し、awkコマンドを使用してテキストファイルの区切り文字にパイプし、 sedを使用して新しい行をマーカーに置き換えますか?

パイプで区切られた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.

これで、シェルスクリプトを使用してこのテキストファイルから値を抽出し、それをシェル変数に保存しています。ここで、シェル変数の値をHTMLファイルの変数に置き換えたいと思います。この代替では、<br /> tagHTMLファイルの出力がすべての3つのセクションに対してテキストファイルと同じ形式になるように、テキストファイル(シェル変数に格納されている)の値で見つかった新しい行を置き換えたいと思います。入力形式は〜のように。

値の抽出と置換に使用するシェルスクリプトは次のとおりです。

#! /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セクションでは見たいです。 注:上記のスクリプト出席者では、Agendaと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本文ファイルではなく、指定されたユーザー入力テキスト領域からのみタグを取得するには、上記のスクリプトで何を変更する必要がありますか?

ベストアンサー1

と交換してください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を使用していて、開始および/または終了を望まない場合は、<br>RSを使用できます。

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

おすすめ記事