文字列置換のためのsedの使用

文字列置換のためのsedの使用
        [Data_Foundation.WF:wf_STG_SIM_RKEM_RKEMMOVE]
    $Param_Object_Name=RKEMMOVE

            [Data_Foundation.WF:wf_STG_SIM_RKEM_RKEMEQBC]
    $Param_Object_Name=RKEMEQBC

            [Data_Foundation.WF:wf_STG_SIM_RKEM_RKEMEQCM]
    $Param_Object_Name=RKEMEQCM

            [Data_Foundation.WF:wf_STG_SIM_RKEM_RKEMLMOV]
    $Param_Object_Name=RKEMLMOV
sed -i 's/[Aa0-Zz9]*.WF:wf_STG_SIM_RKEM_RKEMEQBC/DEF.WF:wf_STG_SIM_RKEM_RKEMEQBC/g' param_file.parm

フォルダ名パターンはData_Foundation DataFoundation Data_Foundation12 DataFoundation12です。

文字列パターン [FOLDERNMAE.WF:$wf_name] フォルダー名 (例: datafoundatio) を EFG (変数) に変更する必要があります。 sed -i 's/[A-Za-z0-9]*.WF:wf_STG_SIM_RKEM_RKEMEQBC/ EFG .WF:wf_STG_SIM_RKEM_RKEMEQBC/g' テスト

上記のsedコマンドを使用すると、次の結果が表示されます。

[Data_EFG.WF:wf_STG_SIM_RKEM_RKEMEQBC]

実際の出力は[EFG.WF:wf_STG_SIM_RKEM_RKEMEQBC]です。

ベストアンサー1

$ cat test.txt
 [Data_Foundation.WF:wf_STG_SIM_RKEM_RKEMMOVE]
    $Param_Object_Name=RKEMMOVE

            [Data_Foundation.WF:wf_STG_SIM_RKEM_RKEMEQBC]
    $Param_Object_Name=RKEMEQBC

            [Data_Foundation.WF:wf_STG_SIM_RKEM_RKEMEQCM]
    $Param_Object_Name=RKEMEQCM

            [Data_Foundation.WF:wf_STG_SIM_RKEM_RKEMLMOV]
    $Param_Object_Name=RKEMLMOV
$
$ echo ${VAR}
EFG
$
$ sed "s/.*\(\.*WF.*$\)/\[$VAR.\1/" test.txt
[EFG.WF:wf_STG_SIM_RKEM_RKEMMOVE]
    $Param_Object_Name=RKEMMOVE

[EFG.WF:wf_STG_SIM_RKEM_RKEMEQBC]
    $Param_Object_Name=RKEMEQBC

[EFG.WF:wf_STG_SIM_RKEM_RKEMEQCM]
    $Param_Object_Name=RKEMEQCM

[EFG.WF:wf_STG_SIM_RKEM_RKEMLMOV]
    $Param_Object_Name=RKEMLMOV

おすすめ記事