I should advise that if your batch reads exactly as you posted, I have no doubt you'd have trouble.
Here's my reformatted version:
@echo off
setlocal EnableDelayedExpansion
rem for /f "delims=" %%x in (C:\FICO\test_script\retcodeStartClientKYC.txt) do (
for /f "delims=" %%x in (q65761009.txt) do (
set "previous=!last!"
set "last=%%x"
)
echo !previous!
set "var1=%last%"
set "var2=%var1:*:=%"
echo %var2%
GOTO :EOF
Noting: You didn't show any sample (if censored) source data from the log file. I used a sample of random text put into a file called q65761009.txt
which suits my system.
Now - to use the code, copy/paste and edit as required into a .bat
file using a proper text editor like Editplus
or Notepad++
(amongst others) - at a pinch, use Notepad
but be aware that batch is oddly layout-sensitive and Notepad
has a horrible habit of trying to reformat when it saves. Save in ANSI format, not Unicode.
Your manipulation is unexplained, unfortunately. As you've coded it, it seems to be echo
ing the second-last line and then removing all text before the first colon in that second-last line, and echo
ing the remainder.
As you've not shown your expectations of the result, we can't be sure of quite what you intended; but that last seems suspect. The crystal ball tells me that you intended to echo
the second-last line (previous
) and the part of the last line after the first colon, so I've modified the code to do that.
Tip : Use set "var1=data"
for setting values - this avoids problems caused by trailing spaces.
Since you are apparently extending a file, you could use >>filename
at the end of each appropriate echo
. Or perhaps you want to create a file anew - containing only the data produced by the two echo
statements; you don't say...
But - I found that the code above generated the two lines (to the console) as (I) expected, and no sign of any of the previous data in the file.