Computing Staff
  • 1

Copy Specific Line Using Batch File

  • 1

I wanna accomplish following using a batch
file:

Search a folder for *.txt files and in each file
search for a specific string and copy only that
specific line containing that string to another
text file (output file).
For example, if contents of the text file (say
Paul.txt) is :

Name : ABCD
Local Folder: //abcdomain/Folder1/Paul.ini
Designation : Programmer

Now I have to open this file and copy the only
line containing the string “domain” ie
Local Folder: //abcdomain/Folder1/Paul.ini
in the output file

Share

3 Answers

  1. Start with mapping your share to a drive, DOS does not really like the \\servername\share syntax. You can map your share like this
    NET USE Z: \\servername\sharename

    • 0
  2. @echo off > newfile & setLocal enableDELAYedeXpansion
    for /f “tokens=* delims= ” %%a in (‘dir/b *.txt’) do (
    find “domain” > newfile
    )

    • 0