批处理文件从文本文件中读取特定字母?

时间:2021-05-06 23:31:03

I have a txt file called named.txt Is there a way to create a batch file to read every letters 2 through 7 letters from every line from name.txt and ignore the rest and output it onto a different txt file called name2.txt. For example I have this in the txt file:

我有一个名为named.txt的txt文件有没有办法创建一个批处理文件来读取name.txt中每行的每个字母2到7个字母,忽略其余部分并将其输出到另一个名为name2.txt的txt文件中。例如,我在txt文件中有这个:

G2010060sample.png
G2010061sample.png
G2010062sample.png
G2010063sample.png

G2010060sample.png G2010061sample.png G2010062sample.png G2010063sample.png

and the batch file would create a new txt file like this :

并且批处理文件将创建一个新的txt文件,如下所示:

2010060.png
2010061.png
2010062.png
2010063.png

2010060.png 2010061.png 2010062.png 2010063.png

2 个解决方案

#1


0  

Excellent online ressource http://ss64.com/nt/syntax.html

优秀的在线资源http://ss64.com/nt/syntax.html

@echo off
if exist output.txt del output.txt
for /f "delims=" %%i in (input.txt) do call :ParseLine %%i
goto :eof


:ParseLine
set line=%1
set line=%line:~1,7%
echo %line%.png>> output.txt
goto :eof

#2


0  

cut -b 2-7,15-18 < infile.txt > outfile.txt

#1


0  

Excellent online ressource http://ss64.com/nt/syntax.html

优秀的在线资源http://ss64.com/nt/syntax.html

@echo off
if exist output.txt del output.txt
for /f "delims=" %%i in (input.txt) do call :ParseLine %%i
goto :eof


:ParseLine
set line=%1
set line=%line:~1,7%
echo %line%.png>> output.txt
goto :eof

#2


0  

cut -b 2-7,15-18 < infile.txt > outfile.txt