How to Merge Lines from 2 Text File without creating a Line Break in Batch Command -


i looking code merge 2 text files without creating line break.

currently using code.

@echo off setlocal enabledelayedexpansion set fd1=\folderpath1\ set fd2=\folderpath2\ set mrgfiles=\outputfolder\ pushd "%fd1%" /f "tokens=1* delims=" %%a in ('dir /b /a-d "!fd1!"') (     if exist "!fd2!\%%a" (         type "%%~fa">"!mrgfiles!\%%a"         echo.>>"!mrgfiles!\%%a"         type "!fd2!\%%a">>"!mrgfiles!\%%a"     ) ) popd 

my setup this

folder 1 has 100 files in it. each file has 1 line example:  line 1  folder 2 has 100 files in it. each file has 1 line. example: line 

the code above manage merge files , output nicely, second line on new line break.

but need newly merged lines in single line.

i tried remove code echo.>>"!mrgfiles!\%%a" merges both lines without space.

how can batch merge lines into

line 1 line line 2 line b 

sorry bad explanation, think code complete cant figure out way merge lines single line.

please me!

thanks

there's easy trick reading text file variable.

@echo off setlocal  set /p "text1="<file1.txt set /p "text2="<file2.txt >merged.txt echo(%text1% %text2% 

that'll take contents of file1.txt , file2.txt, join them on 1 line, , dump concatenated line merged.txt.

the set /p command listens input on stdin. < dumps contents of file stdin, waiting set /p. see this page more info on batch file redirection.


edit: well, apparently lines large method work. that's surprising, thought batch variables handle more 2500 characters. going suggest set /p "= "<nul echo space without line break, set /p refuses pass space (or tab) unless add non-whitespace characters. tried using dbenham's second method of capturing backspace character variable , echoing out text file, didn't work either.

long story short, gave , decided use howitzer swat fly. s.o. not intended free coding service, blast it, refuse defeated problem. here's hybrid batch / jscript script want. save .bat extension.

@if (@a==@b) @end   /* begin jscript multiline comment  :: batch portion  @echo off setlocal set "fd1=\folderpath1\" set "fd2=\folderpath2\" set "mrgfiles=\outputfolder\" pushd "%fd1%"  %%a in (*) (     if exist "%fd2%\%%~a" (         cscript /nologo /e:jscript "%~f0" "%%~a" "%fd2%\%%~a" "%mrgfiles%\%%~a"     ) )  popd  goto :eof  :: end batch portion / begin jscript hybrid */ var fso = new activexobject('scripting.filesystemobject'),     file1 = fso.opentextfile(wsh.arguments(0), 1),     file2 = fso.opentextfile(wsh.arguments(1), 1),     merge = fso.createtextfile(wsh.arguments(2), true);  merge.write(file1.readline() + ' ' + file2.readline()); file1.close(); file2.close(); merge.close(); 

Comments

Popular posts from this blog

python - mat is not a numerical tuple : openCV error -

c# - MSAA finds controls UI Automation doesn't -

wordpress - .htaccess: RewriteRule: bad flag delimiters -