How to delete a line in a text file with bat?

November 15, 2010 at 04:31:06
Specs: Windows Vista, intel core2duo 2.1GHz/3GB
Hallow everyone......I am new to the forum and with bat.
i have a problem.....I want to delete a complete line in a text file with bat.

My text file name is "FLPassBook.txt" (without double quotes)

My FLPassBook.txt contains follow........

C:\Users\INDRAJIT\Desktop\QQQ emc=DDuDuiipOUQx
C:\Users\INDRAJIT\Desktop\New Folder (2)=QQQwwQQq
C:\Users\INDRAJIT\Desktop\DSR Strury=JuJuhyytGtfrFV

I want to delete the second line completely from the FLPassBook.txt
I mean the "C:\Users\INDRAJIT\Desktop\New Folder (2)=QQQwwQQq" (without double quotes)

How to do that?? Can anyone help me?? Please help me...........


See More: How to delete a line in a text file with bat?

Report •


#1
November 15, 2010 at 05:02:25
@echo off > newfile & setLocal enableDELAYedeXpansion

set N=
for /f "tokens=* delims= " %%a in (FLPassBook.txt) do (
set /a N+=1
if !N! neq 2 >> newfile echo.%%a
)


=====================================
Life is too important to be taken seriously.

M2


Report •

#2
November 15, 2010 at 15:17:43
Thank you, Mechanix2Go for your reply................

I have tried code you have posted................

After execution it makes a new file called "newfile" with no extension without the line i have specified in my post.........

But, there is a problem, i don't want any separate file to create.

And the other problem is, the code is just deleting the second line from the text file
but i want to delete a complete line from a text file and i don't know the number count of the line.............It is not your fault it's my fault, because, i wasn't so specific to describe my problem.................


To be very specific, i have a text file named "FLPassBook.txt" (without double quotes) and it have many lines, (i don't know how much) but i know perfectly the text of a specific line which i have to delete, it can be the 2nd line, it can be the 5th line or the 33th whatever.............

And i do not want a code to create any "separate" file as a resulting output.........I want the resulting output to appear into the same file(in that case FLPassBook.txt) and it is very impotent to me..............i am using "Windows Vista Home premium"

End of all, thank u again Mechanix2Go for your reply................


Report •

#3
November 15, 2010 at 17:10:32
find /v "some text" < FLPassBook.txt > #
move /y # FLPassBook.txt


=====================================
Life is too important to be taken seriously.

M2


Report •

Related Solutions

#4
November 16, 2010 at 06:32:36
Bingoooooooooooooo.............

Many Many Thanks Mechanix2Go, your 2nd replied code is just "bulls-eye"
very good trick..........

But, i m really very new to batch programming, about less-then 1 month

That why it is not clear to me that what is the proper work of "< , > , #" (without double quotes & Commas).

Can you please explain me in detail so that i can understand the work of those characters in various situation.............If it is OK, you can include those ~ ` ! @ % ^ & * ( ) _ - + = \ | [ ] { } ' " ; : / ? . , etc. and extended characters work explanation with your post........................

And, truly that will be a great great help for me......................

Again, many many thanks to you for reply Mechanix2Go.........


Report •

#5
November 20, 2010 at 02:55:48
Bingoooooooooooooo.............

Many Many Thanks Mechanix2Go, your 2nd replied code was just "bulls-eye"
very good trick..........

But, i m really very new to batch programming, about less-then 1 month

That why it is not clear to me that what is the proper work of "< , > , #" (without double quotes & Commas).

Can you please explain me in detail so that i can understand the work of those characters in various situation.............If it is OK, you can include those ~ ` ! @ % ^ & * ( ) _ - + = \ | [ ] { } ' " ; : / ? . , etc. and extended characters work explanation with your post........................

And, truly that will be a great great help for me......................

Again, many many thanks to you for reply Mechanix2Go.........


Report •

Ask Question