0

我有一个包含以下几行的 .txt:

#307714 Joana Darc Vitoria Campos 2013-07-14 14:25:27 0.0000
#322521 ALINE MADALENA 2013-07-16 08:31:11 0.0000
#323057 Juliana E Ferreira Araujo 2013-07-16 09:35:36 0.0000
#325581 DIOGO 2013-07-16 14:12:12 0.0000
#326718 Matheus 2013-07-16 16:29:51 0.0000

我已经制作了以下代码,它将从上面的文本中过滤 # 并在单独的批次中替换 #!

所以第一个过滤#如下:

@echo off
if exist id.txt (
    for /f "tokens=1 delims= " %%a in (id.txt) do (
    findstr /c:"%%a" id.txt >nul && (echo %%a >> trials.txt | echo Filtered: %%a to trials.txt)
    )
) else (
    Echo id.txt não existe.. cria o ficheiro e cola lá  a lista de refs para filtragem!
    pause >nul
)

它将过滤 ID 并将它们放在名为 trial.txt 的文本文件中!

之后我用这个代码创建了一个单独的批次,用一个链接替换#:

@echo off
setlocal DisableDelayedExpansion
set INTEXTFILE=trials.txt
set OUTTEXTFILE=test_out.txt
set SEARCHTEXT=#
set REPLACETEXT=Give trial:
set OUTPUTLINE=

for /f "tokens=1,* delims=¶" %%A in ( '"type %INTEXTFILE%"') do (
    SET string=%%A
    setlocal EnableDelayedExpansion
    SET modified=!string:%SEARCHTEXT%=%REPLACETEXT%!

    >> %OUTTEXTFILE% echo(!modified!
    endlocal
)
del /q %INTEXTFILE%
rename %OUTTEXTFILE% %INTEXTFILE%

运行两个批次后的最终结果将是:

Give trial:307714  
Give trial:322521  
Give trial:323057  
Give trial:325581  
Give trial:326718

任何人都知道有什么方法可以将这两个批处理文件放在一个文件中吗?

谢谢 :)

4

1 回答 1

1
for /f "tokens=1 delims=# " %%a in (id.txt) do (
 >>trials.txt echo(#%%a
 >>test_out.txt echo(Give trial:%%a
)

真的不知道您是否需要trials.txt或是否id.txt只包含匹配的行#nnn ...

于 2013-07-23T19:50:09.460 回答