Computer Hope

Microsoft => Microsoft DOS => Topic started by: Xenfire on May 06, 2009, 05:03:40 PM

Title: Delete certain lines of text file?
Post by: Xenfire on May 06, 2009, 05:03:40 PM
I have a text file that has multiple lines in it.

This is line 1
This is line 2
This is line 3

After prompted, a user enters "This is line 2" I want that line to be removed from the file.

However, the lines won't always be in the same place.
Example: (it could be like this)

This is line 3
This is line 1
This is line 2


Help?
Title: Re: Delete certain lines of text file?
Post by: gh0std0g74 on May 06, 2009, 06:58:38 PM
vbscript
Code: [Select]
Set objFS = CreateObject("Scripting.FileSystemObject")
WScript.Echo "Enter line to delete: "
Do While Not WScript.StdIn.AtEndOfLine
   strInput = strInput & WScript.StdIn.Read(1)
Loop
strFile = "c:\test\file.txt"
Set objFile = objFS.OpenTextFile(strFile)
Do Until objFile.AtEndOfLine
strLine = objFile.ReadLine
If Not InStr(strLine,strInput) > 0 Then
WScript.Echo strLine
End If
Loop
Title: Re: Delete certain lines of text file?
Post by: Xenfire on May 06, 2009, 08:20:39 PM
Thanks, but I need the method to be in batch.
Thanks anyways.
Title: Re: Delete certain lines of text file?
Post by: Xenfire on May 07, 2009, 03:15:56 PM
nobody knows?
=[
Title: Re: Delete certain lines of text file?
Post by: Helpmeh on May 07, 2009, 07:09:04 PM
I have a text file that has multiple lines in it.

This is line 1
This is line 2
This is line 3

After prompted, a user enters "This is line 2" I want that line to be removed from the file.

However, the lines won't always be in the same place.
Example: (it could be like this)

This is line 3
This is line 1
This is line 2


Help?
Could this be a de-register?

And can't you just run that from the command prompt?
Title: Re: Delete certain lines of text file?
Post by: Xenfire on May 07, 2009, 08:24:08 PM
Sort of a de-register.
Not exactly, but it's part of it.

It's all experimenting with the banning thing.


And what do you mean "Can't you do that from command prompt"
Title: Re: Delete certain lines of text file?
Post by: Reno on May 07, 2009, 11:41:43 PM
Code: [Select]
@echo off & setlocal

set/p s=enter string :
type test.txt|find/i /v "%s%">$$$
move $$$ test.txt
Title: Re: Delete certain lines of text file?
Post by: Xenfire on May 08, 2009, 06:18:19 PM
Code: [Select]
@echo off & setlocal

set/p s=enter string :
type test.txt|find/i /v "%s%">$$$
move $$$ test.txt

I'll try that.


EDIT: Works great. Much thanks Reno.
Title: Re: Delete certain lines of text file?
Post by: Helpmeh on May 09, 2009, 09:26:30 AM
I'll try that.


EDIT: Works great. Much thanks Reno.
But...the ban function should display that they're banned, this code will just remove them from the registered list.
Title: Re: Delete certain lines of text file?
Post by: Xenfire on May 09, 2009, 03:48:03 PM
I didn't post my code, how would you just figure that I didn't put any notification of ban.

The code is much longer than just removing the user from the list.
and it actually works unlike your ban featawr/
Title: Re: Delete certain lines of text file?
Post by: Helpmeh on May 09, 2009, 03:57:20 PM
I didn't post my code, how would you just figure that I didn't put any notification of ban.

The code is much longer than just removing the user from the list.
and it actually works unlike your ban featawr/

I think I know how it could work...register sends their username to a file...if their name is registered, but not in the file, then they've been banned and are locked out...and did TheFish rage when I didn't unlock it yesterday?
Title: Re: Delete certain lines of text file?
Post by: Xenfire on May 09, 2009, 03:59:43 PM
Fishy exploded with fury.

And the ban does this

when a user is banned, it makes a file with their name in a hidden file (that's why I need the attrib +h thing) Then the other chat components check for the existence of the file.

Pretty simple really.
Title: Re: Delete certain lines of text file?
Post by: Helpmeh on May 09, 2009, 04:01:21 PM
Fishy exploded with fury.

And the ban does this

when a user is banned, it makes a file with their name in a hidden file (that's why I need the attrib +h thing) Then the other chat components check for the existence of the file.

Pretty simple really.
wow...that is much simpler than I expected from you...but it should work in theory...unless they search for their own name and delete it...although they would have to know where it would be placed........
Title: Re: Delete certain lines of text file?
Post by: Xenfire on May 09, 2009, 04:09:14 PM
Which is why I needed the files hidden.
So they won't know the location

and THE SIMPLER THE BETTER.
Why make it complicated when you don't need to?
Title: Re: Delete certain lines of text file?
Post by: Helpmeh on May 09, 2009, 04:10:03 PM
Which is why I needed the files hidden.
So they won't know the location

and THE SIMPLER THE BETTER.
Why make it complicated when you don't need to?
they won't know the location, but they can still find it...but making it hidden will work pretty well.
Title: Re: Delete certain lines of text file?
Post by: Xenfire on May 09, 2009, 04:11:03 PM
especially at school, where the option to view hidden files is restricted for most computers. Except for yours and Zack's
Title: Re: Delete certain lines of text file?
Post by: Helpmeh on May 09, 2009, 04:24:55 PM
especially at school, where the option to view hidden files is restricted for most computers. Except for yours and Zack's
Yeah...sure... :-X