Announcement

Collapse
No announcement yet.

using batch script to delete specific lines to end of file in a text file

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • using batch script to delete specific lines to end of file in a text file

    Hi,

    I want to delete some specific word in a file to the end of the file. Please guide me in doing so or please provide me the program so that i can use it....

    Please use batch commands

    My file looks something like this:

    abc
    bcd
    Drop
    REM--------
    xyz
    asda
    REM------------------
    REM-----------
    DROP DOWN
    REM---------------
    some text
    y
    z



    I want to delete the lines from "DROP DOWN" to end of file. There are many files with the similiar situatiion in a directory and the names of the files are starting with delete and dondelete. I want to delete these lines from all the files.


    I have the below files with similiar text but not the same :
    delete1.txt
    delete2.txt
    dondelete1.txt
    dondelete_me_req.txt

    in Brief all my above txt file has below texts:
    REM------------------
    REM-----------
    DROP DOWN
    REM---------------

    I want to remove these lines to end of file.
    Note: I dont want to create a new file. the existing file should be replaced.


    Please do the needful.

  • #2
    Re: using batch script to delete specific lines to end of file in a text file

    Please use batch commands
    May I inquire why such a restriction?

    Batch script is really not too suitable for file editing. There are way better tools like VBScript or Powershell.

    If you insist on Batch, try scripting edlin. Take a look at Edlin commands. Usage: edlin your-file.txt <your-commands.txt

    -vP

    Comment


    • #3
      Re: using batch script to delete specific lines to end of file in a text file

      Thanks for your response...

      Can you please code the program in VBScript and give it to me. so that i can refer. because i am really new to this.

      Comment


      • #4
        Re: using batch script to delete specific lines to end of file in a text file

        I want to delete the lines from "DROP DOWN" to end of file. There are many files with the similiar situatiion in a directory and the names of the files are starting with delete and dondelete. I want to delete these lines from all the files.



        Code:
         
        # Script DropDown.txt
        var str list, file, content
        # Go to the directory where files are.
        cd "/path/to/the/directory/where/files/are
        # Collect a list of files whose names begin with "delete" and "dontdelete".
        lf -n -r "delete*" > $list ; lf -n -r "dontdelete*" >> $list
        # Go thru files in the list one by one.
        while ($list <> "")
        do
            # Get the next file.
            lex "1" $list > $file
            # Get the contents of the file into a string variable.
            cat $file > $content
            # Cut out everything after "DROP DOWN".
            stex -c "[^DROP DOWN^" $content > null
            # Write the updated $content back to the file.
            echo $content > { echo $file }
        done

        Script is in biter scripting language ( http: //www .biterscripting .com). Copy and paste the script into file C:/Scripts/DropDown.txt, then enter the following command into biterscripting.

        Code:
        script "C:/Scripts/DropDown.txt"

        Please test the script first before using on real files.
        Last edited by Rems; 29th June 2010, 18:22. Reason: live url removed by mod

        Comment

        Working...
        X