# Extract line containing a keyword fro text file



## tigsboy (Nov 25, 2001)

Hi all,

Is there an easy way to extract the entire line in a simple text file
that contains a "keyword" into another file.

For example:

"16/02/2004"," 8:47 AM","Added","EXAMPLE","141607","Bob Builder"
"16/02/2004","10:17 AM","Added","EXAMPLE","140235","Pat Boone"
"16/02/2004","10:47 AM","Added","EXAMPLE","140069","Donald Duck"
"16/02/2004","10:47 AM","Added","EXAMPLE","140563","Robert Rose"
"16/02/2004","10:47 AM","Added","EXAMPLE","140728","James Bond"
"16/02/2004","10:47 AM","Added","EXAMPLE","140751","Nicholas Brown"

If I wanted to extract the entire line with "140069" in it.

Thanks for any help


----------



## AlbertB (Nov 24, 2002)

Using what tigsboy? Is this to be done by writing an app using Java or C++? Or if that hasn't been decided or is overkill what environment is the whole thing set in?

If you can tell us how you need it approached I'm sure someone will be able to offer a solution.


----------



## tigsboy (Nov 25, 2001)

Sorry for the lack of detail. It is a Win2000 system. A simple batch file or Jscript would be fine. We have a log file and simply want to extract the whole line with specified keywords.
Thanks


----------



## dtech10 (Jan 31, 2003)

@echo off
rem get the 5 parameters looking for "@" which should not exist
rem any character not in the lines will do 
rem this gets the comma's as well it thats what you want
rem if you don't want the comma use "delims=," 
rem This is one line
rem Usage: FileName TextToFind 
for /f "tokens=1-5 [email protected]" %%a in (tmp.txt) do echo %%a %%b %%c %%d %%e | find "%1" >> x.txt


----------

