Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Delete certain lines of text file?  (Read 8291 times)

0 Members and 1 Guest are viewing this topic.

Xenfire

    Topic Starter


    Rookie

    Thanked: 1
    Delete certain lines of text file?
    « 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?

    gh0std0g74



      Apprentice

      Thanked: 37
      Re: Delete certain lines of text file?
      « Reply #1 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

      Xenfire

        Topic Starter


        Rookie

        Thanked: 1
        Re: Delete certain lines of text file?
        « Reply #2 on: May 06, 2009, 08:20:39 PM »
        Thanks, but I need the method to be in batch.
        Thanks anyways.

        Xenfire

          Topic Starter


          Rookie

          Thanked: 1
          Re: Delete certain lines of text file?
          « Reply #3 on: May 07, 2009, 03:15:56 PM »
          nobody knows?
          =[

          Helpmeh



            Guru

          • Roar.
          • Thanked: 123
            • Yes
            • Yes
          • Computer: Specs
          • Experience: Familiar
          • OS: Windows 8
          Re: Delete certain lines of text file?
          « Reply #4 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?
          Where's MagicSpeed?
          Quote from: 'matt'
          He's playing a game called IRL. Great graphics, *censored* gameplay.

          Xenfire

            Topic Starter


            Rookie

            Thanked: 1
            Re: Delete certain lines of text file?
            « Reply #5 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"

            Reno



              Hopeful
            • Thanked: 32
              Re: Delete certain lines of text file?
              « Reply #6 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

              Xenfire

                Topic Starter


                Rookie

                Thanked: 1
                Re: Delete certain lines of text file?
                « Reply #7 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.

                Helpmeh



                  Guru

                • Roar.
                • Thanked: 123
                  • Yes
                  • Yes
                • Computer: Specs
                • Experience: Familiar
                • OS: Windows 8
                Re: Delete certain lines of text file?
                « Reply #8 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.
                Where's MagicSpeed?
                Quote from: 'matt'
                He's playing a game called IRL. Great graphics, *censored* gameplay.

                Xenfire

                  Topic Starter


                  Rookie

                  Thanked: 1
                  Re: Delete certain lines of text file?
                  « Reply #9 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/

                  Helpmeh



                    Guru

                  • Roar.
                  • Thanked: 123
                    • Yes
                    • Yes
                  • Computer: Specs
                  • Experience: Familiar
                  • OS: Windows 8
                  Re: Delete certain lines of text file?
                  « Reply #10 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?
                  Where's MagicSpeed?
                  Quote from: 'matt'
                  He's playing a game called IRL. Great graphics, *censored* gameplay.

                  Xenfire

                    Topic Starter


                    Rookie

                    Thanked: 1
                    Re: Delete certain lines of text file?
                    « Reply #11 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.

                    Helpmeh



                      Guru

                    • Roar.
                    • Thanked: 123
                      • Yes
                      • Yes
                    • Computer: Specs
                    • Experience: Familiar
                    • OS: Windows 8
                    Re: Delete certain lines of text file?
                    « Reply #12 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........
                    Where's MagicSpeed?
                    Quote from: 'matt'
                    He's playing a game called IRL. Great graphics, *censored* gameplay.

                    Xenfire

                      Topic Starter


                      Rookie

                      Thanked: 1
                      Re: Delete certain lines of text file?
                      « Reply #13 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?

                      Helpmeh



                        Guru

                      • Roar.
                      • Thanked: 123
                        • Yes
                        • Yes
                      • Computer: Specs
                      • Experience: Familiar
                      • OS: Windows 8
                      Re: Delete certain lines of text file?
                      « Reply #14 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.
                      Where's MagicSpeed?
                      Quote from: 'matt'
                      He's playing a game called IRL. Great graphics, *censored* gameplay.

                      Xenfire

                        Topic Starter


                        Rookie

                        Thanked: 1
                        Re: Delete certain lines of text file?
                        « Reply #15 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

                        Helpmeh



                          Guru

                        • Roar.
                        • Thanked: 123
                          • Yes
                          • Yes
                        • Computer: Specs
                        • Experience: Familiar
                        • OS: Windows 8
                        Re: Delete certain lines of text file?
                        « Reply #16 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
                        Where's MagicSpeed?
                        Quote from: 'matt'
                        He's playing a game called IRL. Great graphics, *censored* gameplay.