/*&cls
@echo off
set @=q&set/an=0x53b7e0b4
title %@%%@% %n%
cd /d "%~dp0"
dir /a-d/b "文本.txt"|cscript -nologo -e:jscript "%~f0" "关键词" "添加的内容"
pause&exit
*/
var fso=new ActiveXObject('Scripting.FileSystemObject');
var keyword=WSH.Arguments(0);
var addstr=WSH.Arguments(1);
while(!WSH.StdIn.AtEndOfStream) {
var file=WSH.StdIn.ReadLine();
WSH.Echo(file);
var txt=read(file);
write(txt, file);
}
function read(file){
var s='';
var f=fso.OpenTextFile(file, 1);
while(!f.AtEndOfStream){
var line=f.ReadLine();
s+=(line.indexOf(keyword)>-1?line+addstr:line)+'\r\n';
}
f.Close();
return s;
}
function write(text, file){
var f=fso.CreateTextFile(file, 2);
f.Write(text);
f.Close();
}
@echo off&setlocal EnableDelayedExpansionfor /f "delims=" %%a in ('type "a.txt"') do ( set t=%%~a findstr /c:"%%~a" "b.txt">>c.txt for /f "delims=" %%i in ('findstr /c:"!t:~,8!" "b.txt"') do ( set t2=%%~i if not "%%~i"=="!t!" ( if "!t2:~,8!!t2:~-4!"=="!t:~,8!!t:~-4!" echo !t2! 1>>d.txt ) ))pause