2015-11-25 66 views
0

嗨,我想用另一個txt文件中的單詞填充txt文件。從其他txt文件中創建帶有特定文本和變量的txt文件

例子:

我有這個txt文件的Source.txt

hi hello 
my name is 
nice to meet you 

而這個txt文件names.txt中

Dave 
Jane 
Tom 
Jill 

想你問的批處理或命令行創建最終.txt與

hi hello 
my name is Dave 
nice to meet you 

hi hello 
my name is Jane 
nice to meet you 

hi hello 
my name is Tom 
nice to meet you 

hi hello 
my name is Jill 
nice to meet you 

預先感謝您。命令行或批處理文件會很好,或者如果存在可以執行此操作的windovs軟件。

+0

我只是希望有人會因爲我的不存在的代碼輸入能力願意幫我 –

回答

0

試試這個:

@echo off 
setlocal enableDelayedExpansion 

:: you can set full file paths to the resource files 
set "source=source.txt" 
set "names=names.txt" 
set "final=final.txt" 

break>"%final%" 
for /f "usebackq delims=" %%a in ("%names%") do (
    set counter=0 
    for /f "usebackq delims=" %%# in ("%source%") do (
     set /a counter=counter+1 
     if !counter! neq 2 (
      (echo(%%#)>>"%final%" 
     ) else (
      (echo(%%# %%a)>>"%final%" 
     ) 
    ) 
    (echo()>>"%final%" 

) 

endlocal 
+0

謝謝你,它的工作 –