首页->【软件工具包使用(SW/Software Tools Usage)】

5 1

将文本a.txt里面的frame1,依次粘贴到b.txt文本里面的abc1~abc8后面,并将frame1的名字 依次改为abc1~abc8

::====Steps of Usage
:: fill the outputname by user[outputname]
:: fill the the parameter of endRow[endRow]
:: set the SrcTset of main tsb file[SrcTset]
:: set the DirTset of sub  tsb  file[DirTset]
:: set the number of tset [TsetNo]
::debug information=======
::for more information pls use the echo
::version:v0.2
::the file name can not be too long
:: Add_function: merge find and replace.
@echo off
color 2
setlocal enabledelayedexpansion
::set the output file of tsb_merge
set dirpath=C:\Users\documents\
set outputname=%dirpath%\a_merge.txt
::this files is used for find and replace,do not change
set tmpdir=%dirpath%\tsc.tmp
::set the total row of file head.
set endRow=7
::copy the output file according to file sizes
::define the number of the tset of main tsb_files
set TsetNo=8
::define the Tset,eg:the main tsb files
::setup the prefix of Tset(change the eqnsetno)
set preTset=abc
::define the Tset,eg:the sub tsb_files
set DirTset=frame1
set vari=1
set cnt=0
:loopc   
    set SrcTset[!cnt!]=%preTset%!vari!
    echo for debug==!SrcTset[%cnt%]!,!cnt!,%preTset%======
    set /a cnt=cnt+1,vari=vari+1
    if !cnt!==%TsetNo% ( goto normal ) else (
    goto loopc)
:normal
::pause
set /a cnt=0
::define the main eqnset and sub eqnset to find & replace
for /f "tokens=* delims=" %%i in ('dir /a-d/s/b %dirpath%\*.txt') do (
    set /a size[!cnt!] = %%~zi, cnt=cnt+1
    set na[!cnt!]=%%i
    echo %%~zi
)
::for debug
::echo %size[0],size[1]%
::echo %na[1],na[2]%::echo.%%a >> tsb.tmp
set /a cnt=0
setlocal enabledelayedexpansion
if not  exist %outputname%  type nul>%outputname%
if %size[0]% gtr %size[1]%  (
::write the file head into the txt file
for /f "tokens=* delims=" %%a in (%na[1]%) do (
      echo.%%a >> %outputname%
      set /a cnt=cnt+1
      if !cnt!==%endRow% goto cpySectionII )
::write the timeset
:cpySectionII
echo i not am here
set /a cnt=0
:loopb
    findstr /i /c:"!SrcTset[%cnt%]!"  %na[1]% >> %outputname%
    call :find_and_Replace %na[2]%,%DirTset%,!SrcTset[%cnt%]!
    :rethoa
    findstr /i /c:"!SrcTset[%cnt%]!"  %tmpdir%>> %outputname%
    del /a /f /q %tmpdir% 2>nul
    set /a  cnt=cnt+1
    if !cnt!==%TsetNo% ( goto endf ) else (
    goto loopb )       
    ) else (
::write the file head
set /a cnt=0
for /f "tokens=* delims=" %%a in (%na[2]%) do (
      echo.%%a >> %outputname%
      set /a cnt=cnt+1
      if !cnt! geq %endRow% goto cpySectionIII )
::write the timeset
:cpySectionIII
echo i am here
set /a cnta=0
:loopa
set str=!SrcTset[%cnta%]!
echo====!cnta!====
findstr /i /c:"!SrcTset[%cnta%]!"  %na[2]% >> %outputname%
call :find_and_Replace %na[1]%,%DirTset%,!SrcTset[%cnta%]!
:rethob
findstr /i /c:"!SrcTset[%cnta%]!" %tmpdir% >> %outputname%
del /a /f /q %tmpdir% 2>nul
set /a  cnta=cnta+1
if !cnta! geq %TsetNo% ( goto endf ) else (
    goto loopa )
    )
::pls change the DirTset in the call module eg,Equ_211_Tim_1_ts1
:find_and_Replace
::echo ===%1,%2====
for /f " eol=* skip=7 tokens=* delims=" %%i in (%1) do (
           set "b=%%i"
           set "b=!b:%2=%3!"
           echo. !b! >> %tmpdir%
           )
if %size[0]% gtr %size[1]% ( goto rethoa ) else (
goto rethob )
:endf
pause
::end of bat file, pls del the pause for normal use.


作者于2018-08-20 22:25:17修改!
楼主可见

  1. shwnyoo 1#

    此程序里面存在一个现象,如果删除脚本文件里面的pause,则bat里面的自增变量将一直自增下去,直到溢出?这是什么问题?