Announcement

Collapse
No announcement yet.

DOS HELP: Delete String inside multiple files in mulitple Directories

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

  • DOS HELP: Delete String inside multiple files in mulitple Directories

    Good Evening - Pretty New to batch scripting so I am looking for some help.

    I currently have multiple files in one directory. I want to search through all the files in that directory and remove a specific string of data from each of the files.

    I want to remove the string of data below from every file in that directory and leave everything else inside the files.


    EX: This is the data inside a file below starting with Volume.

    -Remove

    Volume in drive is CORAPP09_O

    and

    Volume Serial Number is EC14-09B9




    -Actual Data/output inside the file




    Volume in drive is CORAPP09_O
    Volume Serial Number is EC14-09B9
    10/16/2012 03:06 PM 44,961 LCISTARTS-20121016-TSIYB-00.TXT
    10/16/2012 03:06 PM 25,692 LCISTARTS-20121016-TSIYB-01.TXT
    10/16/2012 03:06 PM 32,115 LCISTARTS-20121016-TSIYB-02.TXT
    10/16/2012 03:06 PM 68,512 LCISTARTS-20121016-TSIYB-03.TXT
    10/16/2012 03:07 PM 38,538 LCISTARTS-20121016-TSIYB-04.TXT
    10/16/2012 03:07 PM 23,551 LCISTARTS-20121016-TSIYB-05.TXT
    10/16/2012 03:07 PM 34,256 LCISTARTS-20121016-TSIYB-06.TXT
    7 File(s) 267,625 bytes
    Total Files Listed:
    7 File(s) 267,625 bytes
    0 Dir(s) 173,373,632,512 bytes free

  • #2
    Re: DOS HELP: Delete String inside multiple files in mulitple Directories

    Just to clarify.

    You got a directory with a bunch of text files.
    Inside those text files, there is a string of text that you wish to delete.

    Now removing text from a file is easy if you know the code. The problem is getting it output to the same file as it is being removed from.
    I played around with the below, which outputs the combined data of my 4 test files into a single one.

    @echo off

    Type *.txt | findstr /I /V /C:"Volume in drive is CORAPP09_O">>Testoutput.txt
    Type Testoutput.txt | findstr /I /V /C:"Volume Serial Number is EC14-09B9" >>Testoutput2.txt

    Pause

    So that gets you some info as to what the command looks like to remove the line.
    To get all files output with the same filename more research is needed. However I just got interrupted, and need to do some work, so try this url as reference, and see if it helps

    http://ss64.com/nt/syntax-redirection.html

    Comment


    • #3
      Re: DOS HELP: Delete String inside multiple files in mulitple Directories

      Thank you - This was very helpful.

      Had to tweak it a little bit. One of the lines of string wasn't removing from the txt file. I actually used the last word in the string of data and it new to remove the full string. Wierd - but it worked. Not sure if you can answer why on that.

      Thanks again

      Comment


      • #4
        Re: DOS HELP: Delete String inside multiple files in mulitple Directories

        Not sure, perhaps formatting of the text changed during copy & paste. I also noticed that the space on second line before the >> caused the 2nd line to remain in some of my output files. Removing the space fixed that.

        Have not had a lot of time yet to figure out how to output each file to same name.
        Perhaps if the file names are always the same, (ie file1, file2, file3) you could edit the script to show for example:

        @Echo on

        del temp.txt
        Type file1.txt | findstr /I /V /C:"Volume in drive is CORAPP09_O">>temp.txt
        del file1.txt
        Type temp.txt | findstr /I /V /C:"Volume Serial Number is EC14-09B9">>file1.txt

        del temp.txt
        Type file2.txt | findstr /I /V /C:"Volume in drive is CORAPP09_O">>temp.txt
        del file2.txt
        Type temp.txt | findstr /I /V /C:"Volume Serial Number is EC24-09B9">>file2.txt

        del temp.txt
        Type file3.txt | findstr /I /V /C:"Volume in drive is CORAPP09_O">>temp.txt
        del file3.txt
        Type temp.txt | findstr /I /V /C:"Volume Serial Number is EC14-09B9">>file3.txt

        Pause

        Comment

        Working...
        X