2024年10月22日 星期二

bat 讀檔存成另個檔案

在echo !line!時改成 echo(!line!

可以避免讀到空值時秀出echo is off的訊息

@echo off

setlocal enabledelayedexpansion
for /f "delims=:" %%a in ('findstr /n "AXX0000XXXA" "C:\Users\23456\Desktop\data.txt"') do (set /A find_line=%%a-1)
call :processFile < "C:\Users\23456\Desktop\data.txt" > target.txt
goto :EOF


:processFile

rem Duplicate the first %find_line%-1 lines
for /L %%i in (1,1,%find_line%) do (
   set /P "line="
   echo(!line!
)

rem Insert the additional line
type temp.txt

rem Copy the rest of lines
findstr ^^

exit /B

參考:windows - Why this code says echo is off? - Stack Overflow

沒有留言: