本文介绍了如何使用Windows命令查找文本文件中的字符串,并复制接下来的5个字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有input.txt:
I have input.txt:
asdfasfasdfa,abc12345,abc98591,abc13456,abc95934,abc53455
safasdfasdfa,abc31212,abc55455,abc23124,abc54834,abc13689
...
我需要output.txt:
I need output.txt:
12345
98591
13456
95934
53455
31212
55455
23124
54834
13689
所以我需要找到所有的abc字符串并复制下5个字符)到新文件,每个数字必须在新行。
so I need find all "abc" string and copy next 5 charcters (after "abc") to new file and each number must be in new line.
推荐答案
查看:
@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
这篇关于如何使用Windows命令查找文本文件中的字符串,并复制接下来的5个字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!