Implement batch processing code that outputs two texts in parallel

Source: Internet
Author: User

There are two texts as follows (the actual number of lines of the two texts is unknown ):

20171.txt

Aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
Ccccccccccccccccccccccccccccccccccccccccccc
Eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee
Ggggggggggggggggggggggggggggggggggggggg
Wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww
Zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz

20172.txt

Hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh
Iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii
Bytes

Batch output is required as follows (two texts are output alternately ):

Aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
Hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh
Ccccccccccccccccccccccccccccccccccccccccccc
Iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii
Eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee
Bytes
Ggggggggggggggggggggggggggggggggggggggg

Wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww
Zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz

Requirements:
1. Try not to generate temporary files
2 code efficiency
3. Code as concise as possible
Purpose:
The only purpose is to improve together!

Answer:
More:Copy codeThe Code is as follows: @ echo off
Setlocal enabledelayedexpansion
For/f "delims =" % a in ('Type 11.txt ') do (
Set/a m + = 1
Set "home! M! = %"
)
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:Copy codeThe Code is as follows: @ echo off
For/f "delims =" % I in (1.txt) do set/a n + = 1 & call, set "_ % n % = % I"
For/f "delims =" % I in (2.txt) do set/a m + = 1 & call, 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:Copy codeThe Code is as follows: @ echo off & setlocal enabledelayedexpansion & set n =-1
For/f "delims =" % a in (1.txt) do (
Set/a n + = 1
Set flag =
Call: lp %
If not defined flag echo %
)
: 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 % 1 & echo % a & set flag = a & goto: eof) else echo %
If "% 1" equ "" pause

 

Batman:Copy codeThe Code is as follows: @ echo off
Set "n =-1" & set "flag ="
: 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 % I & if defined flag goto next
Set no =
: Next
For/f "% m % delims =" % I in (2.txt) do echo % I & goto begin
If not defined no set "flag =" & goto begin
Pause> nul

 

Batman:Copy codeThe Code is as follows: @ echo off & setlocal 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.txt & set "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.txt & pause> nul

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.