【问题标题】:Creating txt file with certain text and variables from other txt file使用其他 txt 文件中的某些文本和变量创建 txt 文件
【发布时间】:2016-02-28 07:07:55
【问题描述】:

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

例子:

我有这个txt文件source.txt

hi hello
my name is 
nice to meet you

还有这个txt文件名.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

提前谢谢你。命令行或批处理文件会很好,或者如果存在可以执行此操作的 windows 软件。

【问题讨论】:

  • 我只是希望有人愿意帮助我,因为我不具备代码输入能力

标签: variables batch-file command-line


【解决方案1】:

试试这个:

@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

【讨论】:

    猜你喜欢
    • 2022-01-12
    • 1970-01-01
    • 1970-01-01
    • 2021-09-21
    • 2021-09-17
    • 1970-01-01
    • 2023-02-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多