linux系统,求批量删除文件中指定字符串命令
在一个目录下及其子目录下,所有后缀为htmlhtmxhtmlphpjspaspaspxshtmlrhtmltplmaster的文件,可能包含如下字符串(51.la的统计代...
在一个目录下及其子目录下,所有后缀为html htm xhtml php jsp asp aspx shtml rhtml tpl master的文件,可能包含如下字符串(51.la的统计代码):
<script language="javascript" type="text/javascript" src=" http://js.users.51.la/4299811.js"></script><noscript><a href=" http://www.51.la/?4299811" target="_blank"><img alt="我要啦免费统计" src=" http://img.users.51.la/4299811.asp" style="border:none" /></a></noscript>
自己解决了,办法有些笨:
find . -iname "*.html" -exec sed -i 's/<script.*51.la.*noscript>//' {} \;
find . -iname "*.htm" -exec sed -i 's/<script.*51.la.*noscript>//' {} \;
find . -iname "*.xhtml" -exec sed -i 's/<script.*51.la.*noscript>//' {} \;
find . -iname "*.php" -exec sed -i 's/<script.*51.la.*noscript>//' {} \;
find . -iname "*.jsp" -exec sed -i 's/<script.*51.la.*noscript>//' {} \;
find . -iname "*.asp" -exec sed -i 's/<script.*51.la.*noscript>//' {} \;
find . -iname "*.aspx" -exec sed -i 's/<script.*51.la.*noscript>//' {} \;
find . -iname "*.shtml" -exec sed -i 's/<script.*51.la.*noscript>//' {} \;
find . -iname "*.rhtml" -exec sed -i 's/<script.*51.la.*noscript>//' {} \;
find . -iname "*.tpl" -exec sed -i 's/<script.*51.la.*noscript>//' {} \;
find . -iname "*.master" -exec sed -i 's/<script.*51.la.*noscript>//' {} \; 展开
<script language="javascript" type="text/javascript" src=" http://js.users.51.la/4299811.js"></script><noscript><a href=" http://www.51.la/?4299811" target="_blank"><img alt="我要啦免费统计" src=" http://img.users.51.la/4299811.asp" style="border:none" /></a></noscript>
自己解决了,办法有些笨:
find . -iname "*.html" -exec sed -i 's/<script.*51.la.*noscript>//' {} \;
find . -iname "*.htm" -exec sed -i 's/<script.*51.la.*noscript>//' {} \;
find . -iname "*.xhtml" -exec sed -i 's/<script.*51.la.*noscript>//' {} \;
find . -iname "*.php" -exec sed -i 's/<script.*51.la.*noscript>//' {} \;
find . -iname "*.jsp" -exec sed -i 's/<script.*51.la.*noscript>//' {} \;
find . -iname "*.asp" -exec sed -i 's/<script.*51.la.*noscript>//' {} \;
find . -iname "*.aspx" -exec sed -i 's/<script.*51.la.*noscript>//' {} \;
find . -iname "*.shtml" -exec sed -i 's/<script.*51.la.*noscript>//' {} \;
find . -iname "*.rhtml" -exec sed -i 's/<script.*51.la.*noscript>//' {} \;
find . -iname "*.tpl" -exec sed -i 's/<script.*51.la.*noscript>//' {} \;
find . -iname "*.master" -exec sed -i 's/<script.*51.la.*noscript>//' {} \; 展开
1个回答
展开全部
只是个例子,大概意思。
forecah filename (ls -1 *.html *.htm *.xhtml *.php)
sed -i '1,2d' "$filename"
end
forecah filename (ls -1 *.html *.htm *.xhtml *.php)
sed -i '1,2d' "$filename"
end
追问
先不删除多个文件,我试图删除一个文件中的这些指定字符串也不行,你自己可以试一下,原因估计是,这些字符串被sed命令识别为某种命令了,而不是识别为指定字符串.似乎需要转义符,但不知如何写.
如果能删除一个文件中的,要删除所有文件的,似可以用find命令配合实现.
追答
如果指定字符串,需要对一些字符进行转义,比如!要写成\!。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |