我有以下文件:
. TAU 4236-DA 20
4236-DA - SMS
4236-DA - EMAIL
MID=4236,SC=
{AnyText}
,DABAL1=
{AnyText}
,DAEXP1=
{AnyText}
,MSISDN=
{AnyText}
»
«
. TAU 3065-DA 20
3065-DA - SMS
3065-DA - EMAIL
MID=7364,DABAL1=
{AnyText}
,DAEXP1=
{AnyText}
,MSISDN=
{AnyText}
,USEDVAL=
{AnyText}
,EXCESS=
{AnyText}
»
我想要低于输出:
. TAU 4236 20
4236-DA - SMS
4236-DA - EMAIL
MID=4236,SC=
{AnyText}
,DABAL1=
{AnyText}
,DAEXP1=
{AnyText}
,MSISDN=
{AnyText}
»
«
. TAU 3065 20
3065-DA - SMS
3065-DA - EMAIL
MID=7364,DABAL1=
{AnyText}
,DAEXP1=
{AnyText}
,MSISDN=
{AnyText}
,USEDVAL=
{AnyText}
,EXCESS=
{AnyText}
»
[我想从中删除-DA。 TAU线]。 Plz的帮助。另请注意,文件中有多个字符串代替" -DA"我想删除。喜欢" -DA"," -LA"," -MA"
答案 0 :(得分:1)
您可以使用分组来匹配TAU XXXX
,如下所示:
sed -r 's/(TAU\s+[0-9]{4})-DA/\1 /g' data.txt
当-DA
位于小组-DA
之前时,这会将(TAU\s+[0-9]{4})
替换为3个空格
或awk
:
awk '{ print gensub(/(TAU\s+[0-9]{4})-DA/,"\\1 ","g",$0); }' data.txt