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

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

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

文本1.txt

aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
ccccccccccccccccccccccccccccccccccccccc
eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee
ggggggggggggggggggggggggggggggggggggggg
wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww
zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz

文本2.txt

hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh
iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii
jjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjj


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

aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh
ccccccccccccccccccccccccccccccccccccccc
iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii
eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee
jjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjj
ggggggggggggggggggggggggggggggggggggggg

wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww
zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz

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

答案:
more:
復(fù)制代碼 代碼如下:

@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:
復(fù)制代碼 代碼如下:

@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:
復(fù)制代碼 代碼如下:

@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:
復(fù)制代碼 代碼如下:

@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:
復(fù)制代碼 代碼如下:

@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

標(biāo)簽:常德 煙臺(tái) 連云港 廣安 興安盟 南平 迪慶 青島

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