Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Use Safari to find things more easily in text files Web Browsers
You can use Safari 3.x to open Text files (they must have .rtf or .txt extensions), and then use Safari's Find feature to locate what you're looking for in the file. The advantage is that you get Safari's wonderful new 'find' UI instead of just plain old search results or filtered text.

In context, This is how I use it. There are periods of time when I do a lot of searching through log files. In doing so, I'm often looking for a particular phrase, and I also need to see the log data around that time period. Using Console just doesn't cut it for me, because when I put the search term in, Console blocks out all other data in the file. Opening the log file in TextEdit will allow me to highlight each hit individually, which is better, but still not perfect.

When I use Safari, however, it highlights all of the hits, and grays-out the other text. This allows me to quickly find associations between the search phrase and other things happening at that time. Of course, as mentioned, I do have to get the data into a .txt or .rtf file to do this, but hopefully, Safari will support other plain text extensions in the future. (Right now, if you try to drop a .log file on Safari, it will show you where it is in the Finder.)
    •    
  • Currently 2.33 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (6 votes cast)
 
[9,534 views]  

Use Safari to find things more easily in text files | 16 comments | Create New Account
Click here to return to the 'Use Safari to find things more easily in text files' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Use Safari to find things more easily in text files
Authored by: jvr on May 06, '08 10:48:58AM

Great idea! Apple should implement this Safari-style find in TextEdit.



[ Reply to This | # ]
Use Safari to find things more easily in text files
Authored by: Mark Wilden on May 06, '08 11:02:55AM
Vim does much the same thing. The only difference is that it doesn't gray out the rest of the text, but it can highlight search matches. To use this feature, enter :set hlsearch, then enter /your-search-phrase. To move to the next hit, type n. Also useful is :set incsearch to jump to the first hit as you type. ///ark

[ Reply to This | # ]
Use Safari to find things more easily in text files
Authored by: Anonymous on May 06, '08 03:45:59PM

You can assign a keyboard shortcut to toggle the hlsearch options:
map <F6> :se number!<CR>
map <F7> :set hlsearch!<CR>

in your ~/.vimrc file - then F6 will toggle line-numbers (Which is useful since copy/pasting breaks with line numbers on), and F7 to toggle highlight search



[ Reply to This | # ]
Obligatory
Authored by: jaaronp on May 07, '08 07:21:55AM

Emacs does this too using (by default) Ctrl-S and Ctrl-R



[ Reply to This | # ]
Use Safari to find things more easily in text files
Authored by: pledman on May 06, '08 11:16:33AM

Nice. It seems to choke on UTF encoded text files, however. But the white on gray is nicer than the Firefox yellow highlight.



[ Reply to This | # ]
Use Safari to find things more easily in text files
Authored by: dmmorse on May 06, '08 11:22:28AM

Have you tried TextWrangler? It can find multiple occurrences in multiple files, and returns a list of every hit, which you can then click on to see more context immediately in the results window.



[ Reply to This | # ]
Use Safari to find things more easily in text files
Authored by: brett_x on May 07, '08 11:32:08AM

Yes, I do use TW as well (because it is more powerful, with customizations), but sometimes the Safari UI is just cleaner and more to the point.



[ Reply to This | # ]
Use Safari to find things more easily in text files
Authored by: styrafome on May 06, '08 01:18:21PM

Nice, insightful tip!

I knew that Safari has a better multi-instance Find feature, and I knew that Safari can open some text formats, but somehow I never put 2+2 together...



[ Reply to This | # ]
Use Safari to find things more easily in text files
Authored by: kiwiatcornerpub on May 06, '08 08:07:00PM

I might have missed something, but if you drag any file onto Safari (an icon or window) it will attempt to display it.

One limitation seems to be that it doesn't do the grey-out trick if there are more than 100 instances of the found text.



[ Reply to This | # ]
Use Safari to find things more easily in text files
Authored by: kiwiatcornerpub on May 06, '08 08:11:32PM

Correction - not 'any" file :-)

But it did work with .log files and a few other text files I had lying around including some without an extension. I guess there is some sort of rule here, but it's not obvious to the casual observer.



[ Reply to This | # ]
Use Safari to find things more easily in text files
Authored by: S Barman on May 06, '08 08:09:51PM
You can look at any text file from the command line using grep --context=2 'regular expression' name_of_file. That will get the job done!

[ Reply to This | # ]
Use Safari to find things more easily in text files
Authored by: Mark Wilden on May 08, '08 06:26:26AM
grep --color highlights the hits.

///ark

[ Reply to This | # ]

Use Safari to find things more easily in text files
Authored by: zerobatsu on May 06, '08 10:47:54PM

I use this trick frequently. It's really nice!



[ Reply to This | # ]
Use Safari to find things more easily in text files
Authored by: Mark Wilden on May 07, '08 10:24:17AM

I keep line numbers on and haven't had any problem with copy and paste. I use Carbon Vim, not MacVim. Could you elaborate?

///ark



[ Reply to This | # ]
Use Safari to find things more easily in text files
Authored by: kevingo on May 07, '08 11:24:09AM
Another great tool to do this job on the command line is ack: http://petdance.com/ack.

It is faster than grep, highlights the search hits, and shows any number of surrounding lines around the search hits.

[ Reply to This | # ]
use less
Authored by: el.tyde on May 11, '08 05:46:46PM

While I really like Safari's improved Find interface, there is one signifcant disadvantage in using it for searching text files: it doesn't handle multi-megabyte text files very well. And to some extent, vi(m) is also somewhat slow with large files.

Textmate and other GUI text editors are great overall, but why not use a tool that is pre-installed on every OS X system. So for searching large files, and still having the benefit of your search-pattern highlighted, you should ideally use the "less" utility via Terminal. less is a pager, it loads one page at a time for display, so it is instantaneous in working with enourmously huge files (virtually no size limit). It's quite simple to use; in Terminal type (without the brackets):

less [filepath/yourfilename]

... then to search within your file, type:

/yoursearchpattern

... to go forward, backward, within your file (while still in search-highlight mode) type:

n, or N

... AND, you have the added benefit of being able to make use of some simple regular expressions to make your searches more powerful (in Safari or TextEdit, you can't).

less also holds your search-patterns in memory, if you have not exited your file; so to see or edit your previous searches, just use up-arrow, or down-arrow, after typing / (ie. "slash", to do a search).

--
So remember, less is more.



[ Reply to This | # ]