문자열 교체를 위해 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

관련 정보