Batch script to delete characters

February 25, 2009 at 10:21:22
Specs: Windows XP
Hello.

I'm a complete beginner at scripting and would like some help.

I've got about 1 000 .txt files in a folder and I would like to delete characters in the first line of each file, from position 10 to 18, using a batch script. I can't seem to figure it out by myself. Thanks in advance.




See More: Batch script to delete characters

Report •


#1
February 25, 2009 at 12:03:00
@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
)


=====================================
If at first you don't succeed, you're about average.

M2


Report •

#2
February 26, 2009 at 01:08:48
Thanks!

Working fine, the only problem is that it was in the second line I needed to delete characters. My mistake...

Could you help me with that as well?


Report •

#3
February 26, 2009 at 02:17:18
chande

if !N! equ 1

to:

if !N! equ 2


=====================================
If at first you don't succeed, you're about average.

M2


Report •

Related Solutions

#4
February 26, 2009 at 04:03:59
I have to ask one more thing, what if I want to delete the first 10 characters (spaces) from the beginning of the file?

Report •

#5
February 26, 2009 at 05:46:05
You need to post the first few lines here. Then maybe we can do something.


=====================================
If at first you don't succeed, you're about average.

M2


Report •

#6
February 26, 2009 at 06:56:47
The lines doesn't look right when I paste them in the message box... Maybe if I describe it a bit better. Each .txt file starts with 60 spaces. What I want to do is delete the first 10 of these spaces.

Report •

#7
February 26, 2009 at 08:26:00
Not obvious to me how to do it. I'll give it some thought.


=====================================
If at first you don't succeed, you're about average.

M2


Report •


Ask Question