Get the App
SLTechnology News&Howtos  ›  Development  › 

How to realize batch processing of alternating output of two text peers

Shulou Source: shulou.com Published: 2022-06-03 08:15:45 09月25日 Update

This article is about how to implement batch output alternately between two text peers. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

There are two texts as follows (in practice, we don't know how many lines each of the two texts are):

Text 1.txt

Aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa ccccccccccccccccccccccccccccccccccccccc eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee ggggggggggggggggggggggggggggggggggggggg wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz

Text 2.txt

Hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii jjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjj

The batch output is required as follows (two text output alternately):

Aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh ccccccccccccccccccccccccccccccccccccccc iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee jjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjj ggggggggggggggggggggggggggggggggggggggg wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz

Request:

1 try not to generate temporary files

2 the code should be efficient

3 the code should be as concise as possible

Objective:

The only purpose is to improve together!

Answer:

The code is as follows:

@ echo offsetlocal enabledelayedexpansionfor / f "delims="% an in ('type 11.txt') do (set / a m+=1set "homeowners% a") for / f "delims="% b in (' type 12.txt') do (set / an + = 1set "battalions%% b") if% m% gtr% n% (for / l% c in (11% m%) do (if not "! home%%c!" = "echo! home%%c") ! if not "! bat%%c!" = "" echo! bat%%c!)) Else (for / l%% d in (11% n%) do (if not "! home%%d!" = = "" echo! home% dumped if not "! bat%%d!" = "echo! bat%%d!) pause

Batman:

The code is as follows:

@ echo offfor / f "delims="% I in (1.txt) do set / a nasty callcallcallcallcallcallcallcallcallcallcallreset "_% n% delims="% I "for / f" delims= "% I in (2.txt) do set / a massively callcallcallcallcallcallcallset".% m% 2.txt% I "if% n% gtr% m% (set" num=%n% ") else (set" num=%m% ") for / l% I in (1ma% num%) do (if defined _% I call Echo% i%%if defined.%% I call,echo%%.%% I%%) pause > nul

Pusofalse:

The code is as follows:

Echo off&setlocal enabledelayedexpansion&set n=-1for / f "delims="% an in (1.txt) do (set/a n+=1set flag=call: lp%% aif not defined flag echo% a): lpif "% 1" equ "set/a n+=1set m=skip=%n%if"% m% "equ" skip=0 "set" m = "for / f" m% delims= "% an in (2.txt) do if"% 1 "neq" (echo% 1&echo% a&set flag=a&goto) : eof) else echo% aif "% 1" equ "" pause

Batman:

The code is as follows:

Echo offset "nasty delims= 1" & set "flag=a": beginset / a n+=1if% n% equ 0 (set "m =") else (set "masked skippers% n%") for / f "% m% delims="% I in (1.txt) do echo% i&if defined flag goto nextset no=a:nextfor / f "m% delims="% I in (2.txt) do echo% i&goto beginif not defined no set "flag=" & goto beginpause > nul

Batman:

The code is as follows:

Echo off&setlocal enabledelayedexpansionset "num=0" for% an in (1.txt 2.txt) do (for / f "delims="% I in (% a) do (set / an + = 1if! n! Gtr! num! Set "numb n+=1for!" set / packs%% I > temp.txt) echo. > > temp.txt&set "nasty 0"): lpset / a n+=1for / f "tokens=%n%"%% I in (temp.txt) do echo%% iif% n% neq% num% goto lpdel / Q temp.txt&pause > nul Thank you for your reading! This is the end of this article on "how to achieve batch output of two text peers alternately". I hope the above content can be of some help to you, so that you can learn more knowledge. If you think the article is good, you can share it out for more people to see!

Tags: Text code output two content more purpose article good practical concise practical file article look knowledge answer reference help related Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Linux macOS MySQL Microsoft NVidia