text file delete lines

December 15, 2011 at 02:23:47
Specs: Windows XP
i have multi text file in multi folders
i want delete lines but i want delete lines in current file not new file

See More: text file delete lines

Report •

#1
December 15, 2011 at 08:51:36
To search for a line in a text file, then delete it. Use this.

Example text file
FILE.txt
Loq
Faizan
Admin
Another line
And another line

CODE
@ECHO ON
SET /p search=Search:

FIND "%search%" FILE.txt
IF ERRORLEVEL 1 Goto :NOTFOUND
echo Record Found, Press Y to confirm deletion. Y/N
set YN=
set /p YN=Y/N ? :
IF %YN% == Y goto :DELETE
IF %YN% == N goto :QUIT
Pause

:DELETE
FINDSTR /v /i "%search%" < FILE.txt > FILE2.txt
DEL FILE.txt
REN FILE2.txt FILE.txt
echo DONE
Pause

First you enter a string, if it finds it in the file it will ask to confirm the delete and display the entire line.
When you enter Y, it will copy everything other than the searched string into a new txt file(FILE2.txt) then delete the original, then rename the new file back to the old.

So you end up with the same file but the searched string line removed.

And just another note, using the example text file above, if you search "line". It would display and delete both of the lines which have the word line in.
Hope that helps.

You have WinXP as your OS. The code above was used on an XP machine so it should work, It doesn't seem to work on Win7.


Report •
Related Solutions


Ask Question