[Batch] using a .bat or .cmd file to "Delete a Specific line" from .txt; .reg; .etc

Discussion in 'Scripting' started by searchengine, Jan 30, 2011.

  1. searchengine

    searchengine Guest

    #1 searchengine, Jan 30, 2011
    Last edited by a moderator: Apr 20, 2017
    I recently needed to find a quick way to have a .cmd check for "specific string" in a .reg file, and delete that string and save new .reg file.

    This .cmd or .bat can be used to "Delete" specific line from .txt; .reg; .ini; etc.

    Example .cmd

    so, save the code as anyname.cmd:-

    BLUE=name of file to be checked RED=line of text to delete GREEN=name of file to save

    Code:
    @echo off
    
    Type Test.txt | findstr /I /V /C:"So, lets remove this line" >>Test2.txt
    
    exit
    Example Test.txt

    save this code as Test.txt:-

    Code:
    Example of using a .cmd file to remove a line of text:-
    
    Have a nice day.
    To err is human, but to forgive is divine.
    So, lets remove this line from this text as an example
    We will save edited text, minus the above line.
    now run the "anyname.cmd" while its sitting next to the "Test.txt"; and a new file named "Test2.txt"
    will be produced ... minus the "highlighted" line.
     
  2. tnx

    tnx MDL Expert

    Sep 2, 2008
    1,695
    267
    60
    #2 tnx, Jul 10, 2012
    Last edited: Jul 10, 2012
    On with a small project which seems to be growing by the second.
    I download,ohhh quite some time ago now a "List Maker" app. It works well but,well thought I could make a simple .cmd to do the job.
    Did a bit of surfing and found the simple command to make a list of files in the current directory.
    But this added two lines into the newly made list i did not want.
    the .cmd file and the .txt file it's self..

    Did a bit more searching on how to delete a line from a .txt file and found this.
    Worked well.
    But.....
    I wanted to remove two lines but can not seem to write the right code....

    I got this..
    Then elaberated a bit to this
    i was wondering what is the right way to remove two different lines of text from a .txt
    and could my code be cleaned up ?

    Cheers...

    ohhh yess...

    What about adding extra to a certain line in the .txt doc...Can that be done.

    i.e

    in a text doc there is the line
    "Old Mc Donald"

    can you via a .cmd make this into
    "Old McDonald Had A farm" ( first thing which came into my head )
     
  3. matoly

    matoly MDL Novice

    Feb 20, 2014
    1
    0
    0
    #3 matoly, Feb 20, 2014
    Last edited by a moderator: Apr 20, 2017


    could you please tell me how to do so but save the output in the same file , i dont want to save it in other file
     
  4. Kamrul08

    Kamrul08 MDL Member

    Dec 28, 2013
    104
    13
    10
    You can use nename command first. For example: list.txt is your original file. So you use rename list.txt list_old.txt command first. Then you will be able to save your edited file as list.txt.
     
  5. user_hidden

    user_hidden MDL Expert

    Dec 18, 2007
    1,034
    1,061
    60

    you don't even know any simple DOS commands ?
     
  6. leebo_28

    leebo_28 MDL Senior Member

    Jun 12, 2011
    465
    172
    10
    we have all been there at one time in our life ..true?