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
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.
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
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.
Summary: Hi, I'm trying to figure out the script to delete the '?' character that is randomly appearing in numerous places in a txt file database I have. Any help would be much appreciated. :) ...
Summary: Is it possible for a batch script to delete a single line in a txt file? example: my.txt contains the following: ab cd is it possible to delete cd using batch? ...
Summary: Hi, I am new to batch scripting and need some help from all your genius' out there. I want to write a script that will delete files older than 14 days from a public server at work. I want to leave any...