Solved Append Multiple Text Files As Columns

June 8, 2013 at 13:38:12
Specs: Windows 7

To be honest I checked the post and I didn't understand the examples mentioned there... so could someone help me? For example, I have 3 text files, each one with three lines. I'd like to merge them in a unique text file in columns... As far I could understand I did the code below where it could check the number of text files and lines that the final text file should have :

echo off & setlocal enableDelayedExpansion
for /f %%a in ('dir /b *.txt ^| find /c /v ""') do (
set f = %%a
for /f %%b in ('dir /b *.txt') do (
for /f %%c in (%%b) do (
set l += 1
echo %%c
set /A t = !l!/!f!
echo This report should have !f! columns and !t! lines.
for /l %%d in (1,1,!f!) do (
echo Line %%d

Thank you in advance.

See More: Append Multiple Text Files As Columns

Report •

June 8, 2013 at 17:12:21
✔ Best Answer
@echo off & setlocal enabledelayedexpansion
set z=0
for %%j in (thisfile, thatfile, otherfile) do (
set c=0
for /f "tokens=*" %%a in (%%j) do (
set /a c+=1
call :join %%a
if !c! gtr !z! set z=!c!
(for /L %%a in (1 1 %z%) do echo !foo%%a!)>outfile
:: we could do away with the counter, but only if the variables are guarenteed to
::have unique names (using "foo" for example):
(for /f "tokens=2* delims==" %%a in ('set foo') do echo %%a)>outfile
goto :eof

set foo%c%=!foo%c%!:%1
rem echo !foo%c%!
::===== end batch
note that blank lines are skipped, as written. They can be included if need be.

Report •

June 8, 2013 at 18:26:33
There is some way to change the output format? The current output format is:


I would like to know if is possible to it be like below:


Report •

June 8, 2013 at 19:52:37
@echo off & setlocal enabledelayedexpansion
set x=
(for %%b in (file1 file2 file3) do call :xx %%b)>outfile
goto :eof

for /f "tokens=*" %%a in (%1) do set x=;!x!%%a
echo !x!
set x=

Report •

Related Solutions

Ask Question