Find string, copy line

Microsoft Sql server 2000 standard (full...
January 31, 2010 at 13:02:39
Specs: Windows Server 2000
Hello everybody.
I'm new in scripting and like to have some help for the following "easy" problem.
I'd like to have a script which will read every line of a txt file. If the line contains some specific string, then the line should be copied into a new file.

Who can help me with that?

Thank you!


See More: Find string, copy line

Report •

#1
January 31, 2010 at 13:59:55
set /p text=what text do you want to find?
set /p infile=what file do you want to find it in?
set /p outfile=what file do you want to put it in?
find "%text%" < "%infile%" > "%outfile%"
goto :eof
:--------------------------- snip
:(or commandline:)
:--------------------------- snip
if [%1] equ [] (
echo usage: %0 text-in-quotes inputfile outputfile
) else (
find %1 < %2 > %3
)

Report •

#2
February 1, 2010 at 01:27:31
hello nbrane,

thank you for your help. Will this piece of code check every line of the file? or will it just search for the given string?
Because I really need the script to check every line.
Thx!


Report •

#3
February 1, 2010 at 06:12:40
thank you for your help. Will this piece of code check every line of the file? or will it just search for the given string?
What's the difference?

Report •

Related Solutions

#4
February 1, 2010 at 06:17:11
Hi R2,

I suppose he means does it stop after the first instance.

Fair enough for someone with no experience of FIND.

It checks the whole file.


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

M2


Report •

#5
February 1, 2010 at 07:18:51
I guess he just needs:

findstr /C:"this is" test.txt > c:\output.log

Add the path of the file if you need to
Add /I if you need case insensitively


Report •

#6
February 1, 2010 at 07:21:26
Thank you all for your replies.
That's indeed what I meant, If it would stop after the first instance.

I'm new in scripting and I was expecting something like

While not eof
Read line and search for the string

if string is found then copy line otherwise go to next line
End while

Something like that but then in batch


Report •

#7
February 1, 2010 at 07:42:05
[quote]
I guess he just needs:

findstr /C:"this is" test.txt > c:\output.log

Add the path of the file if you need to
Add /I if you need case insensitively
[/quote]

Thank you TVC, this is just what I need! :)


Report •

Ask Question