Solved Add text from other file to corresponding line in file

August 2, 2012 at 14:31:07
Specs: N/A
Hello,
How can I "merge" two files, but not add text to end - add it to right "side" of it? This illustrates it better:

<File1>
1: SomeText1
2: SomeText2
<File2>
1: AndMore1
2: AndMore2

<Result>
1: SomeText1AndMore1
2: SomeText2AndMore2

Maybe sed, but I don't know how to get specified line from file. That needs loops, doesn't it?


See More: Add text from other file to corresponding line in file

Report •


#1
August 2, 2012 at 18:36:22
✔ Best Answer
if files are not too big, you can store the file content into a set of variables:
@echo off & setlocal enabledelayedexpansion
for /f "tokens=*" %%a in (file1.txt) do (
set t!c!=%%a
set /a c+=1
)
:you now have the whole file in t0..t??, but blank lines are skipped in this particular version
:display test
for /L %%b in (0,1,%c%) do echo !t%%b!
pause
set c=0
for /f "tokens=*" %%a in (file2.txt) do (
call :output "%%a"
set /a c+=1
)
goto :eof
:output
echo %~1----- horizontal merge --- !t%c%!

:end test script
Not sure about your merging specifications: file1:line1=file2:line2, or pattern match.
here's something to start with anyway.


Report •
Related Solutions


Ask Question