Grep和替换仅在中途工作

时间:2015-10-29 15:38:00

标签: regex linux bash shell grep

我写了这个:

grep -lr --include=*.js "eval(function" sitemap.js | xargs sed -i.bak 's/}eval(function[^;]*;/{\n/g'

这是我要移除的代码:

}eval(function(p,a,c,k,e,r){e=function(c){return c.toString(a)};if(!''.replace(/^/,String)){while(c--)r[e(c)]=k[c]||e(c);k=[function(e){return r[e]}];e=function(){return'\\w+'};c=1};while(c--)if(k[c])p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c]);return p}('7 3(e,t,n,a,o,i,m){e.5=o,e[o]=e[o]||3(){(e[o].q=e[o].q||[]).b(p)},e[o].l=e[o].l||+6 4,i=t.8(n),i.9=1,i.c=a,m=t.d(n)[0],m.f.g(i,m)}(h,j,"k","//2.r.s/2/1.u","2");',31,31,'||tj|function|Date|alogObjectName|new|void|createElement|asyn||push|src|getElementsByTagName||parentNode|insertBefore|window||document|script|||||arguments||tongjj|info||js'.split('|'),0,{}))

我的结果是:(只删除了一些。第一位)

if(!''.replace(/^/,String)){while(c--)r[e(c)]=k[c]||e(c);k=[function(e){return r[e]}];e=function(){return'\\w+'};c=1};while(c--)if(k[c])p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c]);return p}('7 3(e,t,n,a,o,i,m){e.5=o,e[o]=e[o]||3(){(e[o].q=e[o].q||[]).b(p)},e[o].l=e[o].l||+6 4,i=t.8(n),i.9=1,i.c=a,m=t.d(n)[0],m.f.g(i,m)}(h,j,"k","//2.r.s/2/1.u","2");',31,31,'||tj|function|Date|alogObjectName|new|void|createElement|asyn||push|src|getElementsByTagName||parentNode|insertBefore|window||document|script|||||arguments||tongjj|info||js'.split('|'),0,{}))

导致我的RegEx中断的原因是什么?如何解决?

目标: 我想删除整个EVAL()字符串/行

1 个答案:

答案 0 :(得分:0)

The eval() call closes on the last parenthesis of the line. You can't match the brackets and parenthesis with sed. You might need to make a program for that.

Otherwise, open your code in a bracket matching editor and remove it manually.