我需要复制一个文本文件的特定行,然后用选定的其他文件替换文件,并用复制的文本行替换相同的行。我有命令行:
@echo off
setlocal ENABLEDELAYEDEXPANSION
set mca=%cd%
cd /d %SYSTEMDRIVE%\PMJ\PROGRAMS\
set programs=%cd%
:select
echo.
echo Which file?
echo.
echo (without.PRG)
echo.
set /p load=
if exist %programs%\%load%.PRG (goto start) else (goto err1)
:err1
echo Not found
goto select
:start
for /F "tokens=*" %%B in (%mca%\mlfb.txt) do (
findstr /B /C:" InterlockingName = " %programs%\%%B > %mca%\actual.txt
set /p "actual= < %mca%\actual.txt"
copy /y %programs%\%load%.PRG %programs%\%%B
fart -a %programs%\%%B " InterlockingName = " %actual%
)
搜索行开始InterlockingName =
然后包含不同的字符。
文件mlfb.txt包含
40AK11600.PRG
40AK11601.PRG
40AK11602.PRG
40AK11603.PRG
40AK11604.PRG
40AK11605.PRG
40AK11637.PRG
40AK11638.PRG
40AK11653.PRG
4OAK11609.PRG
5WK11706.PRG
A2C5330886804.PRG
A2C8171710004.PRG
行
findstr /B /C:" InterlockingName = " %programs%\%%B > %mca%\actual.txt
创建文件actual.txt,其中包含字符串 - 例如
InterlockingName = 40AK11600
命令
copy /y %programs%\%load%.PRG %programs%\%%B
用选定的文件替换一个文件,但我不能用文件actual.txt中的行代替替换文件的行
fart -a %programs%\%%B " InterlockingName = " %actual%
(如果不需要文件actual.txt,可以删除它。)
答案 0 :(得分:0)
使用命令行修改(来自:起点)
:start
for /F "tokens=*" %%B in (%mca%\mlfb.txt) do (
findstr /B /C:" InterlockingName = " %programs%\%%B>%mca%\actual.txt & set /p actual=<%mca%\actual.txt
copy /y %programs%\%load%.PRG %programs%\%%B
findstr /B /C:" InterlockingName = " %programs%\%%B>%mca%\before.txt & set /p before=<%mca%\before.txt
%fart% -a %programs%\%%B "!before!" "!actual!"
)