2

I need copy specific line of one text file, then is file replaced with selected other file and substitute same line with copied text line. I have command line:

@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%
)

Searched line begins InterlockingName = then contains different characters.

File mlfb.txt contains

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

Line

findstr /B /C:"  InterlockingName     = " %programs%\%%B > %mca%\actual.txt

creates file actual.txt, which contains string - for example

InterlockingName     = 40AK11600

Command

copy /y %programs%\%load%.PRG %programs%\%%B

replace one file with selected file, but I can not to substitute line of replaced file with line in file actual.txt

fart -a %programs%\%%B "  InterlockingName     = " %actual%

(if file actual.txt is not needed, it can be eliminated).

bilda
  • 21
  • 4
  • completely different question, but same [solution](http://stackoverflow.com/a/30284028/2152082) (delayed expansion) – Stephan May 17 '15 at 15:34
  • Hi, how can I apply delayed expansion in the command line. I don't know nothing about it. Need I use more ()? – bilda May 18 '15 at 04:54
  • In a batchfile, you enable it with `setlocal enabledelayedexpansion` (When your batchfile ends, there is a implicite `endlocal`). On command prompt itself, you can't do it. However it is possible to start a _new_ command promt with delayed expansion enabled with `cmd /v` (see `cmd /?`) – Stephan May 18 '15 at 05:00

1 Answers1

0

It's working with command line modified (from :start point)

: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!"
)
bilda
  • 21
  • 4