Closed. This question needs details or clarity。它当前不接受答案。
                            
                        
                    
                
                            
                                
                
                        
                            
                        
                    
                        
                            想改善这个问题吗?添加详细信息并通过editing this post阐明问题。
                        
                        3年前关闭。
                                                                                            
                
        
我有以下文件:

.   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行]。请帮助。另请注意,文件中有多个字符串要替换“ -DA”。如“ -DA”,“-LA”,“-MA”

最佳答案

您可以像这样使用分组来匹配TAU XXXX

sed -r 's/(TAU\s+[0-9]{4})-DA/\1   /g' data.txt


-DA在组-DA之前时,它将用3个空格替换(TAU\s+[0-9]{4})

或使用awk

awk '{ print gensub(/(TAU\s+[0-9]{4})-DA/,"\\1   ","g",$0); }' data.txt

关于linux - 使用sed替换solaris中的字符串,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/41426905/

10-10 23:37