Bat file to Delete a Particular Line.....

June 15, 2009 at 21:50:44
Specs: Windows XP SP2, 4 GB
plzzzzz......help me with this.....i need a bat file which deletes a particular line of a txt file.....

such as i have a txt file abc.txt....
and it has following data:-

===

hello......i m computer.........
OS : Windows XP.....

===

I Need the bat file to type "Windows XP" Of the 2nd line in CMD Screen and after that delete the 2nd line of the abc.txt......is that possible....plzzz help me..

where are you Mechanix2Go, DAVEINCAPS.........HELP ME...

=============
hAnSuM KrIsHnA
-a bLACK hAT hACKER
'N'
-a pRO cRACKER
...........................


See More: Bat file to Delete a Particular Line.....

Report •


#1
June 15, 2009 at 22:06:04
you are not putting in your own effort. This is a very simple task and often asked. search the forum first. Otherwise, read a good batch programming guide.

GNU win32 packages | Gawk


Report •

#2
June 16, 2009 at 08:02:13
I'll be happy to let you know that i know how to do this.
I created a Text file database, which adds, views and deletes records in that text file to whatever you search..

Firstly, you create a search, which will search the text file for whatever you typed. Then it displays that record (line)
Then you have the choice to confirm the delete.
Heres how my code goes.

:DELETE
echo.
echo DELETE RECORD
set find=
set /p find=Search:
echo.
echo Search Begun...
echo.
FIND "%find%" Database.txt
IF ERRORLEVEL 1 Goto BAD
echo.
echo Record Found, do you want to delete this record? Y/N
set YN=
set /p YN=Y/N ? :
IF %YN% == Y goto YES
IF %YN% == N goto NO
IF ERRORLEVEL 1 goto BAD2
Pause

:BAD
msg * Error

:BAD2
msg * ERROR

REMEMBER.
Please rename Database.txt to YOUR text file..(e.g. abc.txt in your case)
Also, the Text file MUST be in the same directory as your batch file.

Remeber also to add a menu to your batch file, for example, pressing 1 will go to Add record. 2 will go to delete. or whatever....

You will need to change this code slightly so it works for you, don't copy & paste this code & leave it, it wont work lol.

Hope this has helped.

Matt


Report •

#3
June 17, 2009 at 00:06:23
sorry "Mattio"....u didnt understood.......i want the bat file to display the text "Computer" of 1st line and then delete 1st line of the txt file.....suppose the file was....

===
hello......i m computer.........
OS : Windows XP.....
===

now it will be....

===
OS : Windows XP.....
===

=============
hAnSuM KrIsHnA
-a bLACK hAT hACKER
'N'
-a pRO cRACKER
...........................


Report •

Related Solutions

#4
June 17, 2009 at 02:22:20
Ahha!
Sorry, i missed a bit of code haha.
Ok, on that other piece of code, where to confirm it says
Goto YES
This is the part for YES

:YES
FINDSTR /v /i "%find2%" < Database.txt > Database2.txt
DEL Database.txt
REN Database2.txt Database.txt
echo.
echo DONE
Pause

Thats the code.
Basically, you cannot simply delete a line.

REMEMBER rename Database.txt to your txt file or whatever.

This bit of code Takes out the line u don't want, then it displays the remaining code, then it saves that remaining data into a new text file, then it deletes the old one, then renames the new one.

Hopefully you understand that lol. but it does work.
& Hopefully that is what your looking for.

Matt


Report •

#5
June 17, 2009 at 03:44:08
thnx dude....it worked......got u looking up.....
thnx again....

=============
hAnSuM KrIsHnA
-a bLACK hAT hACKER
'N'
-a pRO cRACKER
...........................


Report •


Ask Question