delete first character on line 5

April 28, 2010 at 05:55:34
Specs: Windows 7
I have a few hundred txt files with numbers in 6 lines (coordinate files).
I want to remove only the first character on line 5.
And want to do it in a batch for all of them.

Found dosens of scripts here, but non seems to do the trick.

See More: delete first character on line 5

Report •

April 28, 2010 at 08:57:56
Best thing is to use the FOR /F loop, reproduce each line, except line 5 where you parse it differently ...

Report •

April 28, 2010 at 10:52:47
Thnx for the reply.
Since I'm not using batch scripting at all, I was hoping for the whole script, if you can spare some time.

Report •

April 28, 2010 at 13:10:35
here's a quick prototype: (not tested!)
@echo off & setlocal enabledelayedexpansion
set extn=txt
for %%a in (*.%ext%) do (
set c=0
set fil=%%a
for /f "tokens=*" %%b in ("%%a") do (
set /a c+=1
if c equ 5 (
set lin=%%b
set lin=!lin:1!
>>temp echo !lin!
) else (
>> temp echo %%b
rem test&debug: check file output at this point
rem NOTE the file is not replaced until tesing is satisfactory
rem then remove the echo
more temp
echo okay?: move temp !fil!

Report •

Related Solutions

April 29, 2010 at 01:27:38
Thnx for the reply.
Tried it, but doesn't seem to work.

Here is an example of a random txt file of my 200 files:


I need to remove the "7" from the begining of line 5

I was fooling around with batch scripts for other purposes, like this:

@echo off & setLocal EnableDelayedExpansion

for /f "tokens=* delims= " %%a in ('dir/b *.txt') do (
set N=0
for /f "tokens=* delims= " %%i in (%%a) do (
set /a N+=1
if !N! equ 1 (
set str=%%i
set front=!str:~0,9!
set back=!str:~18,99!
echo !front!!back! > #
) else (
echo %%i >> #
copy # %%a

this is a script from mechanic2go member and it deletes characters from 10 to 18 on the first row.

But, since I'm not familiar with the meaning of spatial characters I can't modify this for my needs.

Can you direct me to a web resource with some batch script basics - i.e. % means ... %%x is used for...

If you can, please modify your script and try it on my sample file.
Thanks in advance.

Report •

April 29, 2010 at 05:55:42
@echo off > newfile & setLocal enableDELAYedeXpansion

set N=
for /f "tokens=* delims= " %%a in (myfile) do (
set /a N+=1
set S=%%a
if !N! equ 5 ( set s=!S:~1! )
>> newfile echo.!S!

Helping others achieve escape felicity


Report •

April 29, 2010 at 16:47:35
I ALWAYS manage to leave out that squiggly!
not to mention dropping the "n" of %extn%
oh well, maybe i can help the o.p. this much:
to see how the batch components work, from command-prompt:
set /?
for /?
if /?
setlocal /?

then just spend a lot of time experimenting with stuff - it hardly ever works like you think its going to, esp a first,
so don't do anything like del *.* or: FORMAT C:
always echo "destructive" or "hard-to-undo" commands before
actually using them! you can wind up with a real mess once
the for-loops start cranking.

Report •

Ask Question