This batch file can be used for this task:
@echo off
setlocal EnableExtensions DisableDelayedExpansion
set "SourceFolder=D:\WCR"
del "%SourceFolder%\SecondLines.log" 2>nul
for %%I in ("%SourceFolder%\*.txt") do call :ProcessFile "%%I"
endlocal
goto :EOF
:ProcessFile
for /F usebackq^ skip^=1^ delims^=^ eol^= %%L in (%1) do (
>>"%SourceFolder%\SecondLines.log" echo %~nx1: %%L
goto :EOF
)
goto :EOF
Please note that command FOR ignores always empty lines. So if the second line is an empty line, the next non empty line is written into the LOG file.
The log file is created in source directory. For that reason it is important that the log file has not file extension txt
.
For understanding the used commands and how they work, open a command prompt window, execute there the following commands, and read entirely all help pages displayed for each command very carefully.
call /?
del /?
echo /?
endlocal /?
for /?
goto /?
set /?
setlocal /?
See also: