bat 批处理 找到指定字符串就在文本最后加一行字符串

如图,有一个文件夹,里面有很多sql,如何用bat遍历里面的sql,查找sql中有“create table”语句的
如 create table claim
则在此文件最后面加上 grant select,update,insert on claim to admin;其中claim是变量如果查找的create table是其他表,那么最后加的也要改变。
下面是效果图

@echo off
for %%a in (*.sql) do (
    for /f "tokens=2*" %%b in ('findstr /r /c:"create table .*" "%%a"') do (
        if "%%b" neq "" >>"%%a" (echo;&echo;grant select,update,insert on %%c to admin;)
    )
)
pause

及时采纳回答

温馨提示:答案为网友推荐,仅供参考
相似回答