主頁 > 知識庫 > 實現(xiàn)兩個文本同行交替輸出的批處理代碼

實現(xiàn)兩個文本同行交替輸出的批處理代碼

熱門標簽:沈陽電銷 外呼獲客系統(tǒng) 四川防封電銷卡套餐 aa專業(yè)電話外呼系統(tǒng) 浙江語音外呼系統(tǒng)招商 用電話機器人取代人工 95專業(yè)外呼線路是怎么回事 谷歌地圖標注錯位 無錫極信防封電銷卡價格
有兩個文本如下(實際中并不知道兩文本各有多少行):

文本1.txt

aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
ccccccccccccccccccccccccccccccccccccccc
eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee
ggggggggggggggggggggggggggggggggggggggg
wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww
zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz

文本2.txt

hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh
iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii
jjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjj


要求用批處理輸出如下(兩文本交替輸出):

aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh
ccccccccccccccccccccccccccccccccccccccc
iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii
eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee
jjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjj
ggggggggggggggggggggggggggggggggggggggg

wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww
zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz

要求:
1 盡量不生成臨時文件
2 代碼要高效
3 代碼盡量簡潔
目的:
唯一的目的在于共同提高!

答案:
more:
復制代碼 代碼如下:

@echo off
setlocal enabledelayedexpansion
for /f "delims=" %%a in ('type 11.txt') do (
set /a m+=1
set "home!m!=%%a"
)
for /f "delims=" %%b in ('type 12.txt') do (
set /a n+=1
set "bat!n!=%%b"
)
if %m% gtr %n% (
for /l %%c in (1 1 %m%) do (
if not "!home%%c!"=="" echo !home%%c!
if not "!bat%%c!"=="" echo !bat%%c!
)
) else (
for /l %%d in (1 1 %n%) do (
if not "!home%%d!"=="" echo !home%%d!
if not "!bat%%d!"=="" echo !bat%%d!
)
)
pause

 

batman:
復制代碼 代碼如下:

@echo off
for /f "delims=" %%i in (1.txt) do set /a n+=1call,set "_%%n%%=%%i"
for /f "delims=" %%i in (2.txt) do set /a m+=1call,set ".%%m%%=%%i"
if %n% gtr %m% (set "num=%n%") else (set "num=%m%")
for /l %%i in (1,1,%num%) do (
if defined _%%i call,echo %%_%%i%%
if defined .%%i call,echo %%.%%i%%
)
pause>nul

 

pusofalse:
復制代碼 代碼如下:

@echo offsetlocal enabledelayedexpansionset n=-1
for /f "delims=" %%a in (1.txt) do (
set/a n+=1
set flag=
call :lp %%a
if not defined flag echo %%a
)
:lp
if "%1" equ "" set/a n+=1
set m=skip=%n%
if "%m%" equ "skip=0" set "m="
for /f "%m% delims=" %%a in (2.txt) do if "%1" neq "" (echo %1echo %%aset flag=agoto :eof) else echo %%a
if "%1" equ "" pause


 

batman:
復制代碼 代碼如下:

@echo off
set "n=-1"set "flag=a"
:begin
set /a n+=1
if %n% equ 0 (set "m=") else (set "m=skip=%n%")
for /f "%m% delims=" %%i in (1.txt) do echo %%iif defined flag goto next
set no=a
:next
for /f "%m% delims=" %%i in (2.txt) do echo %%igoto begin
if not defined no set "flag="goto begin
pause>nul

 

batman:
復制代碼 代碼如下:

@echo offsetlocal enabledelayedexpansion
set "num=0"
for %%a in (1.txt 2.txt) do (
for /f "delims=" %%i in (%%a) do (
set /a n+=1
if !n! gtr !num! set "num=!n!"
set /p=%%i nul>>temp.txt
)
echo.>>temp.txtset "n=0"
)
:lp
set /a n+=1
for /f "tokens=%n%" %%i in (temp.txt) do echo %%i
if %n% neq %num% goto lp
del /q temp.txtpause>nul

標簽:常德 煙臺 連云港 廣安 興安盟 南平 迪慶 青島

巨人網(wǎng)絡通訊聲明:本文標題《實現(xiàn)兩個文本同行交替輸出的批處理代碼》,本文關鍵詞  實現(xiàn),兩個,文本,同行,交替,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請?zhí)峁┫嚓P信息告之我們,我們將及時溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡,涉及言論、版權(quán)與本站無關。
  • 相關文章
  • 下面列出與本文章《實現(xiàn)兩個文本同行交替輸出的批處理代碼》相關的同類信息!
  • 本頁收集關于實現(xiàn)兩個文本同行交替輸出的批處理代碼的相關信息資訊供網(wǎng)民參考!
  • 推薦文章