windows - Batch - Zigzag merging with two files -


i make zigzag merging of 2 text files following. have 2 files in input:

file1.txt a 

and

file2.txt b b b 

i have output:

output.txt b b b 

can please tell me may simpliest way in batch (i'm forced use native windows langage). thank you!

if can assume number of lines in both files equal, work:

@echo off type nul>output.txt setlocal enabledelayedexpansion set linecount=0  /f %%i in (file1.txt) set /a linecount=!linecount!+1  /l %%n in (1,1,!linecount!) (     /f "tokens=1* delims=:" %%a in ('findstr /n .* "file1.txt"') (         if "%%a"=="%%n" set linea=%%b     )     /f "tokens=1* delims=:" %%a in ('findstr /n .* "file2.txt"') (         if "%%a"=="%%n" set lineb=%%b     )     echo !linea! >> output.txt     echo !lineb! >> output.txt ) 

the first loop count lines in file1.txt. second loop iterates on number of lines. both internal loops execute command findstr /n .* "filex.txt" on file1.txt , file2.txt. /n parameter outputs content of file adding : @ beginning of each line. split each modified line delimeter : , store after : if line starts current line index incremented after each interation. after n-th iteration of "big" loop !linea! contains contains n-th line of first file , !lineb! contains n-th line of second file , both lines appended output.txt.


Comments

Popular posts from this blog

python - No exponential form of the z-axis in matplotlib-3D-plots -

php - Best Light server (Linux + Web server + Database) for Raspberry Pi -

c# - "Newtonsoft.Json.JsonSerializationException unable to find constructor to use for types" error when deserializing class -