Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xslt/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Batch file 使用findstr的批处理文件循环_Batch File - Fatal编程技术网

Batch file 使用findstr的批处理文件循环

Batch file 使用findstr的批处理文件循环,batch-file,Batch File,上面的代码适用于findstr的第一行//引用,但我希望对文本文件的每一行执行相同的操作 如何做到这一点?如果有多行匹配,按照您对文件的编码方式,将只处理最后一次出现的内容(在循环过程中覆盖以前的值) 将代码分开,创建一个子例程,并为每次出现调用此子例程 @echo off rem Let findstr to find the LINE you want (only once): for /f "delims=" %%a in ('findstr "to_timestamp" t1.txt')

上面的代码适用于findstr的第一行//引用,但我希望对文本文件的每一行执行相同的操作


如何做到这一点?

如果有多行匹配,按照您对文件的编码方式,将只处理最后一次出现的内容(在循环过程中覆盖以前的值)

将代码分开,创建一个子例程,并为每次出现调用此子例程

@echo off
rem Let findstr to find the LINE you want (only once):
for /f "delims=" %%a in ('findstr "to_timestamp" t1.txt') do set "_line=%%a"
SET _line2=%_line:*to_timestamp=%
SET _line3=%_line2:*)=%
set _rep_str=('07-10-13 07:07:29','%%d-%%m-%%y %%h:%%i:%%s')
CALL SET _result=%%_line:%_line2%=%%
CALL SET _result2=%%_line2:%_line3%=%%
CALL SET _result=%%_line:%_line2%=%%
CALL SET _result=%_result:to_timestamp=STR_TO_DATE%
echo %_result%%_rep_str%%_line3% >> Output.txt

::echo %_rep_str% >> Output.txt
::echo %_line3% >> Output.txt
PAUSE

你能给我们一些输入和预期输出的样本吗?可能会让你更容易理解你的问题。
@echo off
    rem Let findstr to find the LINE you want (only once):
    for /f "delims=" %%a in ('findstr "to_timestamp" t1.txt') do call :doWork "%%a"
    ....
    ....
    PAUSE
    exit /B

:doWork
    SET "_line=%~1"
    SET _line2=%_line:*to_timestamp=%
    SET _line3=%_line2:*)=%
    set _rep_str=('07-10-13 07:07:29','%%d-%%m-%%y %%h:%%i:%%s')
    CALL SET _result=%%_line:%_line2%=%%
    CALL SET _result2=%%_line2:%_line3%=%%
    CALL SET _result=%%_line:%_line2%=%%
    CALL SET _result=%_result:to_timestamp=STR_TO_DATE%
    echo %_result%%_rep_str%%_line3% >> Output.txt

    ::echo %_rep_str% >> Output.txt
    ::echo %_line3% >> Output.txt

    goto :EOF