大家好,我正在处理如下文字:
war {
dependencies {
runtime project(':project1')
runtime project(':project2')
...
runtime project(':project20')
}
我想替换文本中的一些字符串,特别是将此值13A更改为14B,在行中:
"AF|AFFSDFSFASDFS|Archive" "Yes"
"AF|AFFSDFSFASDFS|Name" "LOCALggr"
"AF|AFFSDFSFASDFS|AFFAckAssocCd" ""
"AF|AFFSDFSFASDFS|AFFAckCommID" "fsdf"
"AF|AFFSDFSFASDFS|AFFAckLevel" "fsdf Supported"
"AF|AFFSDFSFASDFS|AFFAckRqst" "No Requedfst"
"AF|AFFSDFSFASDFS|AFFAckTestInd" "Test"
"AF|AFFSDFSFASDFS|AFFAckVersion" "fsdfs"
"AF|AFFSDFSFASDFS|AFFCharSet" "13A"
"AF|AFFSDFSFASDFS|AFFCommAgreeID" ""
"AF|AFFSDFSFA13A13|AFFICCheckCtlNo" "fsdf"
"AF|AFFSDFSFASDFS|AFFICLstRcvdCtlNo" "fsdfs"
我想要的输出是:
"AF|AFFSDFSFASDFS|AFFCharSet" "13A"
我试过了:
"AF|AFFSDFSFASDFS|AFFCharSet" "14B"
我得到了:
sed "s/13A/14B/g" test.txt > test2.txt
该命令运行良好,但问题是它也影响与字符串匹配的行,如:
"AF|AFFSDFSFASDFS|Archive" "Yes"
"AF|AFFSDFSFASDFS|Name" "LOCALggr"
"AF|AFFSDFSFASDFS|AFFAckAssocCd" ""
"AF|AFFSDFSFASDFS|AFFAckCommID" "fsdf"
"AF|AFFSDFSFASDFS|AFFAckLevel" "fsdf Supported"
"AF|AFFSDFSFASDFS|AFFAckRqst" "No Requedfst"
"AF|AFFSDFSFASDFS|AFFAckTestInd" "Test"
"AF|AFFSDFSFASDFS|AFFAckVersion" "fsdfs"
"AF|AFFSDFSFASDFS|AFFCharSet" "14B"
"AF|AFFSDFSFASDFS|AFFCommAgreeID" ""
"AF|AFFSDFSFA14B13|AFFICCheckCtlNo" "fsdf"
"AF|AFFSDFSFASDFS|AFFICLstRcvdCtlNo" "fsdfs"
并将其更改为:
"AF|AFFSDFSFA13A13|AFFICCheckCtlNo" "fsdf"
但我不想要它,我只是想影响引号内的值,我想获得这个输出:
"AF|AFFSDFSFA14B13|AFFICCheckCtlNo" "fsdf"
我想了解如何实现这一结果的任何建议。
答案 0 :(得分:1)
你试过报价吗?
sed 's/"13A"/"14B"/g' test.txt > test2.txt