Computing.Net > Forums > Programming > Batch script to delete characters

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Batch script to delete characters

Reply to Message Icon

Name: lothar129
Date: February 25, 2009 at 10:21:22 Pacific
OS: Windows XP
Subcategory: Batch
Comment:

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.





Sponsored Link
Ads by Google

Response Number 1
Name: Mechanix2Go
Date: February 25, 2009 at 12:03:00 Pacific
Reply:

@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


0

Response Number 2
Name: lothar129
Date: February 26, 2009 at 01:08:48 Pacific
Reply:

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?


0

Response Number 3
Name: Mechanix2Go
Date: February 26, 2009 at 02:17:18 Pacific
Reply:

chande

if !N! equ 1

to:

if !N! equ 2


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

M2


0

Response Number 4
Name: lothar129
Date: February 26, 2009 at 04:03:59 Pacific
Reply:

I have to ask one more thing, what if I want to delete the first 10 characters (spaces) from the beginning of the file?


0

Response Number 5
Name: Mechanix2Go
Date: February 26, 2009 at 05:46:05 Pacific
Reply:

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


0

Related Posts

See More



Response Number 6
Name: lothar129
Date: February 26, 2009 at 06:56:47 Pacific
Reply:

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.


0

Response Number 7
Name: Mechanix2Go
Date: February 26, 2009 at 08:26:00 Pacific
Reply:

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


0

Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Batch script to delete characters

Batch Script to delete '?' character in txt www.computing.net/answers/programming/batch-script-to-delete-character-in-txt/19908.html

Batch File To Delete Line www.computing.net/answers/programming/batch-file-to-delete-line/15539.html

batch file to delete folders/files www.computing.net/answers/programming/batch-file-to-delete-foldersfiles/16164.html