正規表現を使用してシェルスクリプトでキャプチャグループの内容を置き換える方法

正規表現を使用してシェルスクリプトでキャプチャグループの内容を置き換える方法

複数のディレクトリにファイルを入力し、既存のインデックス名をindex = windows_prとindex = windows_npに変更しようとしています。

表示された WinEventLog ブロックはすべて input.conf と同じファイルにありますが、A.(EVZ_pr_windows/inputs.conf) や B(DEG_np_windows/inputs.conf) など、異なる名前のフォルダーにあります。したがって、_prで終わるインデックスを持つすべてのファイルセクションはフォルダA inputs.confにあり、_npで終わるインデックスを持つすべてのファイルセクションはフォルダB input.confにあります。スクリプトは、_prで終わるインデックスをindex = windows_prに変更し、_npで終わるインデックスをindex = windows_npに変更する必要があります。

input.conf の WinEventLog ブロックは、アプリケーション、セキュリティ、システム、ForwardedEvents、および設定に制限されます。

これを試しましたが、エラーが発生しました

以下はエラーです

\]_,/s/.*index.*=.*pr$/index = window_pr/' inputs.conf

sed: -e 式 #1、文字 69: 終了していないアドレス正規表現

#!/bin/bash

sed -E -i '\_\[WinEventLog://(Application|Security|System|ForwardedEvents|Setup)
\]_,/s/.*index.*=.*np$/index = window_np/' inputs.conf

sed -E -i '\_\[WinEventLog://(Application|Security|System|ForwardedEvents|Setup)
\]_,/s/.*index.*=.*pr$/index = window_pr/' inputs.conf


[WinEventLog://Application]
checkpointInterval = 5
current_only = 0
disabled =0
start_from = oldest
index = CNDO_pr

[WinEventLog://Security]
checkpointInterval = 5
current_only = 0
disabled =0
start_from = oldest
index = CGWS_pr

[WinEventLog://System]
checkpointInterval = 5
current_only = 0
disabled =0
start_from = oldest
index = DMRW_pr

[WinEventLog://ForwardedEvents]
checkpointInterval = 5
current_only = 0
disabled =0
start_from = oldest
index = NENP_pr

[WinEventLog://Setup]
checkpointInterval = 5
current_only = 0
disabled =0
start_from = oldest
index = EOFK_pr

[WinEventLog://Application]
checkpointInterval = 5
current_only = 0
disabled =0
start_from = oldest
index = FDWD_np

[WinEventLog://Security]
checkpointInterval = 5
current_only = 0
disabled =0
start_from = oldest
index = ASKD_np

[WinEventLog://System]
checkpointInterval = 5
current_only = 0
disabled =0
start_from = oldest
index = JMSF_np

[WinEventLog://ForwardedEvents]
checkpointInterval = 5
current_only = 0
disabled =0
start_from = oldest
index = JCCD_np

[WinEventLog://Setup]
checkpointInterval = 5
current_only = 0
disabled =0
start_from = oldest
index = HSMS_np

ベストアンサー1

エラーメッセージを考慮して式#1が始まると仮定すると、\\_式の文字69が_続くようです]。したがって、式に適切なターミネータを提供する\にはプレフィックスが必要だと思います。_

おすすめ記事