views:

49

answers:

2

Hi, 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:

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

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

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

A: 
cut -b 2-7,15-18 < infile.txt > outfile.txt
Radomir Dopieralski
The 15-18 part is only guaranteed to get the extension if the filenames are all 14 chars long.
Instantsoup
Plus cut is not available on Windows unless you install it with cygwin or something similar.
Radomir Dopieralski
A: 

Excellent online ressource 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
Philibert Perusse
Thanks you so much!! works great but there a problem. When I run it again it repeats the names all over. Is there a way to stop repeating the names. It shows 2010060.png2010061.png2010062.png2010063.png2010060.png2010061.png2010062.png2010063.png
steven
I don't quite get what you mean by repeating names. This very simple batch takes your input.txt and generates an output.txt... if the names repeat themselves in input.txt that is a shame. You may want to create your input.txt automatically with a line like this: dir /b G*.png>input.txt just before using input.txt in the for /f.
Philibert Perusse