zoukankan      html  css  js  c++  java
  • 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

  • 相关阅读:
    关于springMVC+Mybatis jar包详解
    关于struts2的过滤器和mybatis的插件的分析
    C# Zip压缩、解压
    JS 字符串转字节截取
    JS 时间差计算 XX秒前、XX小时前、XX天前
    IIS配置web.config 将带www域名转为不带www域名
    JavaScript获取当前url路径
    SQL 查询今天、昨天、7天内、30天的数据
    SQL求解两个时间差
    SqlServer获取当前日期
  • 原文地址:https://www.cnblogs.com/MarvelYoung/p/7155005.html
Copyright © 2011-2022 走看看