1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

Extract line containing a keyword fro text file

Discussion in 'Software Development' started by tigsboy, Apr 12, 2004.

Thread Status:
Not open for further replies.
Advertisement
  1. tigsboy

    tigsboy Thread Starter

    Joined:
    Nov 25, 2001
    Messages:
    86
    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
     
  2. AlbertB

    AlbertB

    Joined:
    Nov 24, 2002
    Messages:
    2,438
    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. :)
     
  3. tigsboy

    tigsboy Thread Starter

    Joined:
    Nov 25, 2001
    Messages:
    86
    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
     
  4. dtech10

    dtech10

    Joined:
    Jan 31, 2003
    Messages:
    53
    @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
     
As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 733,556 other people just like you!

Loading...
Similar Threads - Extract line containing
  1. DemerNkardaz
    Replies:
    0
    Views:
    440
Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/219847

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice