这样行不 (运行前请先备份文件)- @if(0)==(0) ECHO OFF
- CScript.exe //NoLogo //E:JScript "%~f0" "1.txt"
- PAUSE&GOTO :EOF
- @end
- var fso = new ActiveXObject('Scripting.Filesystemobject');
- var text = fso.OpenTextFile(WScript.Arguments(0),1);
- var arr = text.ReadAll().split(/\n/);
- text = fso.OpenTextFile(WScript.Arguments(0),2,true)
- WScript.StdOut.Write("行号:");
- var len = WScript.StdIn.ReadLine();
- WScript.StdOut.Write("旧字符串:");
- var oldstr = WScript.StdIn.ReadLine();
- WScript.StdOut.Write("新字符串:");
- var newstr = WScript.StdIn.ReadLine();
- arr[len-1] = arr[len-1].replace(new RegExp("\\b"+oldstr+"\\b",'gi'),newstr);
- text.Write(arr.join('\n'));
- text.Close()
复制代码
|