How to delete text from a text file

February 21, 2012 at 21:44:56
Specs: Win 7 Pro, 4.17Ghz 8GB ram
I have this scrip from Wahine

@echo off
setlocal enabledelayedexpansion

for /f "tokens=*" %%1 in (input.txt) do (
set inline=%%1

if /i "!inline:~0,2!" equ "id" (set /a ctr+=1
set outfile=output!ctr!.txt

echo !inline!>>!outfile!

dir output*.txt

it does exactly what I need it to do. It gets the id string down till it hits another id string and puts that in a sperate file. But I would also like it to delete those lines from the input.txt file

is there a simple modification that can be made to this script?

See More: How to delete text from a text file

Report •

February 23, 2012 at 00:12:39
I don't understand what you want to achieve. Your earlier post shows that the lines to be copied are all that the input file contains, do you just want to delete the input file on completion of splitting it into individual files? If so just add a Del command line to the end of the script to delete input.txt.

Report •

February 23, 2012 at 20:32:54
the file has a multiple different strings of x,y,z,and c coordinates. The script above grabs the specific id that each set has in it. I want to delete that one set of coordinates once it is in a different text file.

ex after it grabbed:

and put it into output_1.txt

it will delete it from the source text file.

there could be hundreds of id's in the source file.

Report •

February 24, 2012 at 16:17:43
Not possible, batch scripting language cannot delete any content from a file in situ, the file must be re-written without the text to be deleted. If it were possible all you'd end up with is an input file with nil content.

Report •

Related Solutions

Ask Question