使用来自其他txt文件的某些文本和变量创建txt文件

时间:2015-11-25 13:12:47

标签: variables batch-file command-line

您好我想用另一个txt文件中的单词填充txt文件。

示例:

我有这个txt文件source.txt

hi hello
my name is 
nice to meet you

这个txt文件names.txt

Dave
Jane
Tom
Jill

您是否要求批处理或命令行使用

创建final.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软件。

1 个答案:

答案 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