Solved Help with interlacing two text files

May 12, 2017 at 14:02:34
Specs: Windows 10
Hi, I'm trying use a batch file to merge two text files into one. However, I need the output to be the first 10 lines of File1, followed by the first line of File2, then the next 10 lines of File1...

File2 will always be shorter than File1. Also, it would be nice if the new file ended after the last line of File2 was merged, but that's not absolutely necessary.

Can anybody give me a hand? I can't imagine this is too difficult, however I'm extremely rusty and I'm finding it difficult to find examples of merging text in this manner.

See More: Help with interlacing two text files

Report •

May 12, 2017 at 18:22:23
✔ Best Answer
If you're really on Win10, you should probably use a PowerShell script instead, since MS is more actively depreciating batch.

$file1 = gc someFile.txt -read 10
gc someOtherFile.txt | 
 foreach -Begin { $line = 0 } {
 } |
 Out-File newFile.txt

How To Ask Questions The Smart Way

message edited by Razor2.3

Report •

May 13, 2017 at 15:07:54
That worked perfect. Thanks!

Report •

May 14, 2017 at 06:08:48
::======  script starts here  ===============
:: get 10 lines from fist + 1 frin second
:: atrus.bat  2017-05-13 14:26:59.09
@echo off > NEWFILE & setLocal enableDELAYedeXpansioN

for %%V in (F S C N S10) do set %%V=

for /f "tokens=* delims= " %%a in (first.txt) do (
set /a N+=1 & set S!N!=%%a
if defined S10 (
  call :sub1
  if defined S11 (
    for /L %%V in (1 1 11) do echo.!S%%V!
  set S10=
  set N=
goto :eof

set S11=
set C=
set/a F+=1
for /f "tokens=* delims= " %%i in (second.txt) do (
set /a C+=1 & if !F! equ !C! set S11=%%i
goto :eof
::======  script ends here  =================


M2 Get custom script or take private lessons

Report •
Related Solutions

Ask Question