computing
  • 11

Windows Batch File: Extracting Lines Of Text

  • 11

I have only written a few batch files and I have only done very simple things to automate my work. I have a big analysis to do and I really need help automating it or it will be impossible. I have 100 text files that are output from a program. I would like to go through the 100 files and extract a single line of text from each to copy into a new file that would contain all 100 lines in the same file. The line begins with a unique string followed by 16 numbers. There are spaces between the string and the numbers. As an example,
uniquestring 1.0 128 32 32 22 22 27 0 5.5 7.6 10.8 1.0 2.0 1.0 4.0 13.0
I would really appreciate any help.

Share

1 Answer

  1. At prompt type mybat Folder_Name where Folder_Name is the folder holding your 100 text files.

    :: MYBAT.BAT Usage mybat Folder_Name
    @ech off
    pushd %*
    if exist FileNew.txt del FileNew.txt
    for %%j in (*.txt) do type "%%j" | find "uniquestring" >> FileNew.new
    ren FileNew.new *.txt
    popd
    :: End_Of_Batch
    

    • 0