Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.

How do you search a text file fast and output only the results?

heres what I have to work with, I have a whole bunch of logs, the logs look like (see below)

2010-09-11 00:04:17|J|16| michael|

2010-09-11 00:04:17|J|11| Wayne|

2010-09-11 00:04:18|J|6| James|

2010-09-11 00:04:18|J|7| Trianglered|

2010-09-11 00:04:18|J|3| Matthew|

2010-09-11 00:04:18|J|1| ktate|

2010-09-11 00:04:18|J|4| Mishnecof|

2010-09-11 00:04:18|J|9| Jason|

2010-09-11 00:04:18|J|10| Grunt|

2010-09-11 00:04:24|J|5| John|

2010-09-11 00:05:47|J|1| Ken|

2010-09-11 00:05:54|J|2| Mitch|

what I would like to do is search these logs for certian things and then have them output to a page or SOMETHING, sure I could use ctrl+f but searching threw a log with litterly THOUSANDS of lines take a LOOOONG time now the catch is this (X = values that WILL change)

X|J|X| Mitch|

what I want to search for is |J| and there name (in my logs this means they joined) so I can't use ctrl+f now because there is the value that can change BETWEEN there name & J.....

Update:

Alrighty, so I tried the BATCH suggestion, I get 'The system cannot find the file logfile.name.'

Update 2:

Alrighty, fixed my 1st question ;D durr lol, now I can't seem to find this 'newfile.txt'

3 Answers

Relevance
  • 1 decade ago
    Favorite Answer

    Recommend windows application Replace Pioneer, its quite easy to extract the required line from a text file. No coding required.

    How to extract all lines that match "X|J|X| Mitch|"?

    1. install "Replace Pioneer" and launch

    2. ctrl-o open your log file(text format)

    3. ctrl-h open 'Replace' window

    * set 'Replace Unit' to 'Line'

    * set 'Search for pattern' to:

    .*?\|J\|.*?\| Mitch\|(Note: .*? means any chars, \| means column)

    * set 'replace with pattern' to:

    $match\n(Note:$match means the line that matches, \n means newline character)

    * uncheck option of "Print unmatched Unit"(means discard rest lines)

    4. click "Replace", done!

    In your case, you will get following result in a new page:

    2010-09-11 00:05:54|J|2| Mitch|

    Replace Pioneer free trial and examples download at:

  • ?
    Lv 7
    1 decade ago

    If you have any programming skills it would be a simple matter to write a quick & dirty program to read this test file as input and then act accordingly on whatever you wanted to do.

    However, since you asked the question, that leads me to believe that is not an option for you.

    Another method might be to simply sort this text file by a certain column or columns. Most quality text editors (like TextPad) can sort on several different keys, that you specify. You also might be able to load it into, say Excel, and then sort the columns as you saw fit.

  • 1 decade ago

    Here's a solution in BATCH

    @echo off

    del newfile.txt 2>nul

    for /f "tokens=1-4delims=|" %%a in (logfile.name) do (

    if %%b==J if " %%d"=="%1" >>newfile.txt echo %%a %%b %%c %%d

    )

    Save this in a file called 'process.bat' then from the command-prompt type

    process Matthew

    and the 'Matthew' line will appear in the file newfile.txt

    * Note that the above IS case-sensitive for %%a..%%d.

    * It is also case-sensitive for 'Matthew'. You could change

    if " %%d"=="%1"'

    to

    if /i " %%d"=="%1"

    to make it case-insensitive for the parameter (ie it would match for "MATTHEW" or "mAtTHeW"...)

    see newsgroup alt.msdos.batch.nt for lots of similar techniques...

Still have questions? Get your answers by asking now.