有没有办法使用批处理文件查找和替换JavaScript代码?下面是一个示例:
查找:<script type="text/javascript" src="http://www.mega.edu/Course/WebCTfooter/footer.js">Footer</script>
替换:<script type="text/javascript" src="http://www.mega.edu/Course/WebCTfooter/footer_ungrad.js">Footer</script>
任何帮助都将不胜感激。
发布于 2012-11-20 21:34:21
因为你可以使用python,所以我建议使用python程序而不是批处理文件,可能是这样的:
#!/usr/bin/python
import shutil
import sys
import re
for path in sys.argv[1:]:
print "processing " + path
infile = open(path,'r')
tmpfile = open(path+'.tmp','w')
# make the replacements
for line in infile:
line = re.sub("/footer.js","/footer_ungrad.js",line)
line = re.sub("/header.js","/header_ungrad.js",line)
line = re.sub("/sample.js","/sample_ungrad.js",line)
tmpfile.write(line)
infile.close()
tmpfile.close()
# now move it back to the original file
shutil.move(path+'.tmp',path)使用python 2.4进行了测试。
https://stackoverflow.com/questions/13463056
复制相似问题