Windows 下脚本处理

公司需要处理SQL的脚本问题,每个文件删除最后3行,文件数目较多,本来是别人的活,但是他解决不了,我就帮忙看了下,最后解决完毕,比网上有的速度快得多,主要是理解了for这个命令,会产生序号,而不用自己去单独产生序号,那样很麻烦。

for /f "tokens=*" %%d in ('dir /ad /b') do (
     cd %%d
     for /f "tokens=*" %%f in ('dir /b *.sql') do (
          findstr /c:"use paradb;" %%f && goto fir_end
          echo use paradb; > temp.temp
          echo. >> temp.temp
          type "%%f" >> temp.temp
         del "%%f"
         ren temp.temp "%%f"
:fir_end
         rem "end one cir"
     )
    cd ..
)

:sec
set ERRORLEVEL=0
for /f "tokens=*" %%f in ('dir /a-d /b *.sql') do (
     if "%%f" == "histable.sql" (
     findstr /c:"use hisdb;" %%f && goto sec_end
           echo use hisdb; > temp.temp
     ) else (
     findstr /c:"use paradb;" %%f && goto sec_end
           echo use paradb; > temp.temp
     )
     echo. >> temp.temp
     type "%%f" >> temp.temp
     del "%%f"
     ren temp.temp "%%f"
:sec_end
     rem "end one cir"
)

@echo off

call:delline xxx.sql 1

goto EOF
:delline
set file=%1
for /f "tokens=2 delims=:" %%i in ('find /c /v ".*" %file%') do set /a res=%%i-%2

 (for /f "tokens=1* delims=:" %%a in ('findstr /n .* %file%') do ( 

      if %%a geq %res% goto MOV  //这个地方知道%a,技巧满分,初学的人不知道,试了好久才知道。

      echo.%%b)) > temp.temp

      goto EOF
:MOV
     del /f /q %file%
     ren temp.temp %file%
goto EOF

:EOF

转载于:https://www.cnblogs.com/MarvelYoung/p/7155005.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值