用sed / awk / perl删除字符串模式

时间:2015-03-26 11:22:12

标签: unix awk sed

我想做这个替换:

"name1"."name2"()="name3"."name4" 

使用Sed我试过了:

sed -e 's/\"[[:alpha:]]*\"\.\"[[:alpha:]]*\"\=\"[[:alpha:]]*\"\.\"[[:alpha:]]*\"//g'

没有成功。

NeronLeVelu建议的解决方案

echo '"NAME1"."NAME2"="NAME3"."NAME4"'|sed -e 's/"[[:alnum:]]*"\."[[:alnum:]]*"="[[:alnum:]]*"\."[[:alnum:]]*"//g'

它只使用一次:

但是在一个更复杂的字符串中不起作用...... :-( 在--AIX 6 1 ---

>cat /tmp/bbbb 
case when "D"."COD_COMP"="B"."COD_COMP" AND "D"."COD_CNL"="B"."COD_CNL" AND "D"."COD_PUN"="B"."COD_PUN" AND "D"."COD_UNTA"="B"."COD_UNTA" 

>cat /tmp/bbbb|sed -e 's/"[[:alnum:]]*"\."[[:alnum:]]*"="[[:alnum:]]*"\."[[:alnum:]]*"//g' case when "D"."COD_COMP"="B"."COD_COMP" AND "D"."COD_CNL"="B"."COD_CNL" AND "D"."COD_PUN"="B"."COD_PUN" AND "D"."COD_UNTA"="B"."COD_UNTA" –

任何人都可以帮助我?

1 个答案:

答案 0 :(得分:0)

sed -e 's/"[[:alnum:]_]*"\."[[:alnum:]_]*"\(()\)\{0,1\}="[[:alnum:]_]*"\."[[:alnum:]_]*"\([[:space:]]\{1,\}AND[[:space:]]\{1,\}\)\{0,1\}/YourReplacementString/' YourFile
  • "=
  • 无法逃脱 由于中的数字,
  • 使用[:alnum:]代替[:alpha:]
  • 添加_-
  • 之类的字符
  • 添加可选的缺失()
  • 添加强制性AND(如果有)