Copy specific line using batch file

January 21, 2010 at 06:33:17
Specs: Windows 2003
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


See More: Copy specific line using batch file

Report •


#1
January 21, 2010 at 08:18:50
@echo off > newfile & setLocal enableDELAYedeXpansion

for /f "tokens=* delims= " %%a in ('dir/b *.txt') do (
find "domain" < %%a >> newfile
)


=====================================
Helping others achieve escape felicity

M2


Report •

#2
January 21, 2010 at 08:29:19
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


Report •

#3
January 21, 2010 at 08:33:29
One liners:

2>nul type *.txt | find "domain" >> "newfile"

or

findstr /l "domain" *.txt >> "newfile"


Batch Variable how to


Report •

Related Solutions

#4
January 21, 2010 at 08:43:36
Nothing to do with DOS nor shared drive.


=====================================
Helping others achieve escape felicity

M2


Report •

#5
January 21, 2010 at 08:54:12
You're right, I was a bit confused by the question, was thinking the file itself was inside such a folder, hmm

Report •


Ask Question