Reputation: 89
i want to write a batch file to find a particular string in a file. If the string is found then i want to redirect the whole line which contains the string to another file. for ex:
suppose a file myfile.txt contains the following text
abcwerthfdh
qwerewtretywr
weqreqwrtabcwerwe
wqerweqabcqwewq
when i launch the batch file giving myfile.txt and abc as command line arguments, then the output should be into a file called newfile.txt and it should contain only the lines which contain the text "abc". if i run this code again it should append to newfile.txt and not delete existing contents. in this case it should push the lines 1, 3 and 4 into newfile.txt
Upvotes: 0
Views: 5313
Reputation: 37589
@echo off&setlocal
for /f "delims=" %%a in ('findstr "%~2" "%~1"') do (echo(%%a)>>newfile.txt
Upvotes: 2