Luiz Vaughan
Luiz Vaughan

Reputation: 675

Merge lines of text in ONE big column using BATCH

I have several hundreds of different txt files (ranging from TXT1 to TXT 2000), located in a single folder and I would like to merge all TXTs as follows using batch:

TXT1             TXT2           TXT2       etc      TXT2000    
line 001       line 101       line 501              line 90000
(...)           (...)          (...)                   (...)
line 100       line 500       line 550              line 100000

Before merging, the first two lines of each TXT file should be deleted. After merging I would have a single file TXTall.txt as:

TXTall
line 003
line 004
(...)
line 100000

Any help?

Upvotes: 0

Views: 307

Answers (1)

Blorgbeard
Blorgbeard

Reputation: 103447

You can do this with the copy command:

copy TXT*.txt TXTall.txt

This will append all files with names matching TXT*.txt together and save the whole thing into a file called TXTall.txt.

I'm not sure whether you can rely on the ordering being sensible. I suggest you test it and see if works for you.

Update: To skip the first two lines of each file, try this:

@echo off
for %%f in (txt*.txt) do (
    for /F "delims= skip=2" %%t in (%%f) do (
        echo %%t >> AllTxt.txt
    )
)

Upvotes: 1

Related Questions