3

So here is the situation. I currently run a mail server for my small non-profit company. My mail server (Merak Mail Server) keeps logs in .log files and mail as .tmp files. Essentially these are just text files that are kept on the server.

Problem is that when I put text into the "Containing text" field on Windows Explorer, it always misses the files and tells me no results returned. Then when I search the files one by one (painful at best), I find the files I need.

Do I not understand the search feature well enough, or maybe I have it indexing wrong. I really don't care what I need to use to search the files, even a third-party app is fine with me, I just want to type an email address into a box and search all of my log files or email files and find out which one I am looking for. It can be Windows Search or something else, as long as I can find a way to get the job done I will be happy. Pay solutions are fine as well.

Thanks everyone in advance.

Matt
  • 433
  • 1
  • 5
  • 10
  • Its probably because windows uses file extensions to identify files, and .tmp could be binary or text. Just a guess though. –  Jun 18 '09 at 16:23

16 Answers16

8

I'd say give WinGrep a shot.

chaos
  • 7,463
  • 4
  • 33
  • 49
  • gotta say, I love this program. It does exactly what I want it to do. Thanks chaos. – Matt Jun 18 '09 at 18:38
  • 1
    update on this program, WinGrep after performing like a champ died with "Out of rescourses" error. Uninstall and install did not fix it so I am now using grepWin. Not as powerful, but it works for what I need. – Matt Jun 26 '09 at 17:50
  • 1
    I should point out that WinGrep isn't free. – djangofan Mar 18 '10 at 15:46
4

Use findstr at the command prompt!

C:\>findstr /?
Searches for strings in files.

FINDSTR [/B] [/E] [/L] [/R] [/S] [/I] [/X] [/V] [/N] [/M] [/O] [/P] [/F:file]
        [/C:string] [/G:file] [/D:dir list] [/A:color attributes] [/OFF[LINE]]
        strings [[drive:][path]filename[ ...]]

  /B         Matches pattern if at the beginning of a line.
  /E         Matches pattern if at the end of a line.
  /L         Uses search strings literally.
  /R         Uses search strings as regular expressions.
  /S         Searches for matching files in the current directory and all
             subdirectories.
  /M         Prints only the filename if a file contains a match.    
  etc.


Example:
C:\>findstr /s /m my.name@domain.com c:\temp\*.txt c:\temp\*.log
c:\temp\t\t.log
c:\temp\t\t.txt
c:\temp\t\tt.log
c:\temp\tt.txt

Redirect to a file and open in notepad:
C:\>findstr /s /m my.name@domain.com c:\temp\*.txt c:\temp\*.log > c:\temp\myemail.txt & notepad c:\temp\myemail.txt 
4

If they're all in a single directory, I can see a two step process helping you out.

Step 1: Command-line

Open a CMD shell and go to the directory you're looking for. Then issue the find command:

F:\directory> find "user.name@org.org" *

It'll then search all files in that directory for the string you're looking for. When it finds one, it'll give you the file name, like this:

---------- MSGTRK20090603-1.LOG
2009-06-03T09:11:37.486Z,192.168

Which will tell you which file to go searching inside.

Step 2: Searching inside the file

This step you already know. The first step is just narrowing your search scope.

sysadmin1138
  • 131,083
  • 18
  • 173
  • 296
  • so I love this solution, but am having troubles making it work correctly. When I put in "searchstring" * I get all of the files in the directory. When I only put in "searchstring", it just hangs. even on one file located in a directory by itself. What am I doing wrong? – Matt Jun 18 '09 at 18:06
  • Without a file-name it assumes it is searching on standard-in, piped from another command. Using the "*" at the end tells it to search all files in the directory. On files it gets a hit, it'll return the line that string returned on. The "---------- MSGTRK20090603-1.LOG" in the above is the file-name the line was found inside. – sysadmin1138 Jun 18 '09 at 18:10
  • that is what I thought, on the return of the filename, but it returns all files in th directory, not just the ones that contain my search string. – Matt Jun 18 '09 at 18:16
2

You can do this one of 2 ways (well I'm sure there are more but here is what I would do)

  1. Install Microsoft Desktop Search, you can do this on the server or a workstation and have it index the files. It should be able to see they are text files and index the contents. This will be the faster of the 2 ways. This is free btw.

  2. Use an advanced text editor like Notepad++ or Textpad and use the file in files option which will seach though all the files in the directory. But this will take longer when you need to run the search. Notepad++ is free, Textpad has a small cost but is free to try.

If this is something you need to do frequently, I'd go with 1. If its infrequent every now and then thing, try out 2 and see if it works for you.

SpaceManSpiff
  • 2,547
  • 18
  • 19
2

I like UltraEdit for this. You can tell it to seach all the files in a directory (or limit it to certain file types or any other wildcard) for a string you specify. If it finds your text in multiple files or multiple times in a file, it gives you a list of all the instances it found and clicking on one takes you to that file/location.

Ward - Reinstate Monica
  • 12,788
  • 28
  • 44
  • 59
2

Use powershell then:

select-string -path c:\mylogfiledir*.log -pattern "my string"

Note that in powershell v2 you can also use the -context switch to get the lines above and below the line where the match was found

Jim B
  • 23,938
  • 4
  • 35
  • 58
1

You can use ack 'A grep-like program specifically for large source trees'. Ack is like grep but written in perl (works fine on Windows). These are the reasons why it is supposedly better than grep:

  1. It's blazingly fast because it only searches the stuff you want searched.
  2. ack is pure Perl, so it runs on Windows just fine.
  3. The standalone version uses no non-standard modules, so you can put it in your ~/bin without fear.
  4. Searches recursively through directories by default, while ignoring .svn, CVS and other VCS directories. * Which would you rather type? $ grep pattern $(find . -type f | grep -v '.svn') $ ack pattern
  5. ack ignores most of the crap you don't want to search * VCS directories * blib, the Perl build directory * backup files like foo~ and #foo# * binary files, core dumps, etc
  6. Ignoring .svn directories means that ack is faster than grep for searching through trees.
  7. Lets you specify file types to search, as in --perl or --nohtml. * Which would you rather type? $ grep pattern $(find . -name '.pl' -or -name '.pm' -or -name '*.pod' | grep -v .svn) $ ack --perl pattern Note that ack's --perl also checks the shebang lines of files without suffixes, which the find command will not.
  8. File-filtering capabilities usable without searching with ack -f. This lets you create lists of files of a given type. $ ack -f --perl > all-perl-files
  9. Color highlighting of search results.
  10. Uses real Perl regular expressions, not a GNU subset.
  11. Allows you to specify output using Perl's special variables * Example: ack '(Mr|Mr?s). (Smith|Jones)' --output='$&'
  12. Many command-line switches are the same as in GNU grep: -w does word-only searching -c shows counts per file of matches -l gives the filename instead of matching lines etc.
  13. Command name is 25% fewer characters to type! Save days of free-time! Heck, it's 50% shorter compared to grep -r.
chmeee
  • 7,270
  • 3
  • 29
  • 43
  • As much as I love ack, grep is the better choice here. None of ack's snazzy features are relevant to log searching. – Andy Lester Jun 18 '09 at 19:01
1

I never you the windows search/find, because of things like this. I usually end up doing a search through a good old command prompt. The results are 99% much faster and more accurate then the Search/Find GUI.

c:
cd \
dir /s *.log *.tmp

You can even pipe the results into the Find command if you want to search within the results.

mrTomahawk
  • 1,119
  • 1
  • 10
  • 17
  • this will return all of the files of that type, but what about searching inside of each of the files for text. Is that what sysadmin1138 solution does? – Matt Jun 18 '09 at 18:02
  • that's where the Find command comes into play i.e. dir \ /s *.log *.tmp |find "something" |more – mrTomahawk Jun 19 '09 at 13:42
1

Don't forget Logparser can be a good Text parser/search utility as well. The 'TEXTWORD and TEXTLINE input' formats and the 'CSV and TSV input' formats are worth running the logparser -i:INPUTFORMATYOUWISHTOKNOWMOREABOUT -h 'help' call on. There are examples within the 'help' files, too.

mctsonic
  • 437
  • 2
  • 4
1

I use Agent Ransack and it works great. It also attaches it self to the right-click menu so you can right click the folder and say Agent Ransack and it will search there. Oh and best thing, it's free.

I use this to search inside text files as well as temp folders that normal Search from Windows won't search.

Hope it helps.

Hondalex
  • 693
  • 4
  • 8
0

I'd say this is a job for WildReplace . WildReplace is totally free and its good for just searching through text files such as .xml files.

Wildreplace does everything that grepWin and WinGrep will do and displays the results better in my opinion.

djangofan
  • 4,172
  • 10
  • 45
  • 59
0

Windows does not actually search all files for text. See article http://support.microsoft.com/kb/309173. It is possible to add registry entries that will add to the types of files that this style of search will find.

Wesley
  • 32,320
  • 9
  • 80
  • 116
Bill
  • 1
0

I use PsPad (a free advanced text editor) to do similar log searches. If you go to Search -> Search / Replace in files you can search any text string in a set of files in a specific directory.

colemanm
  • 659
  • 5
  • 10
  • 25
0

If you'd like to use windows explorer:

Click Change preferences Change files and folder search behavior Make sure "advanced" is selected

Click more advanced options Make sure "hidden files and folders" is selected

Then Tools Folder options View tab Check "show hidden files and folders" Uncheck "hide extensions for known file types" Uncheck "hide protected operating system files"

MathewC
  • 6,877
  • 9
  • 38
  • 53
0

I do logfile (and other text file searches) with a copy of GNU grep (for windows) which was downloaded and put in the directory of the files I want to scan (or put it in your path)

Then, at the command prompt type

grep -H email@example.org *.tmp>>output.txt

This will give you an output file with the filenames (and the line with the email address).

hellimat
  • 129
  • 2
0

Windows search by default searches filenames in non-indexed locations and it searches for filenames and its contents in indexed locations. But you can change this if you go to Tools->Folder Options->Search tab.

If you can't find your file extension in the indexing list, you can add it from the advanced indexing options:

enter image description here

It's surprising no one talked about this.

fmysky
  • 94
  • 6