2

我有 input.txt:

asdfasfasdfa,abc12345,abc98591,abc13456,abc95934,abc53455  
safasdfasdfa,abc31212,abc55455,abc23124,abc54834,abc13689  
...

我需要输出.txt:

12345  
98591  
13456  
95934  
53455  
31212  
55455  
23124  
54834  
13689  

所以我需要找到所有“abc”字符串并将接下来的 5 个字符(在“abc”之后)复制到新文件中,并且每个数字都必须在新行中。

4

1 回答 1

3

一探究竟:

@echo OFF &SETLOCAL
FOR %%f IN (*.txt) DO (
    ECHO Processing %%f --^> %%~nf.txt.new
    (for /f "usebackq delims=" %%a in ("%%~f") do call:doit "%%a")>"%%~nf.txt.new"
)
GOTO :EOF

:doit
SET "line=%~1"
SET "first=true"
:loop
SET "token="
FOR /f "tokens=1*delims=," %%b IN ("%line%") DO (
    SET "token=%%b"
    SET "line=%%c"
)
SET "out=%token:~-5%"
IF NOT DEFINED first ECHO(%out%
SET "first="
IF DEFINED line GOTO :loop
GOTO :EOF
于 2013-07-10T06:35:59.063 回答