Windows 下指令碼處理

來源:互聯網
上載者:User

標籤:use   自己   需要   rem   問題   序號   his   off   file   

公司需要處理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

Windows 下指令碼處理

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.