Pick of the Week - Nov 10 [Show all picks]
Path Finder 5 - A feature-laden Finder replacement
Submit Hint Search The Forums LinksStatsPollsFAQHeadlinesRSS
12,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 0.00 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (0 votes cast)
 
[6,188 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 whomever 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 Tue, May 6 2008 at 10:48AM PDT
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 Tue, May 6 2008 at 11:02AM PDT
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: mr_dbr on Tue, May 6 2008 at 3:45PM PDT
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 Wed, May 7 2008 at 7:21AM PDT
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 Tue, May 6 2008 at 11:16AM PDT
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 Tue, May 6 2008 at 11:22AM PDT
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 Wed, May 7 2008 at 11:32AM PDT
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 Tue, May 6 2008 at 1:18PM PDT
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 Tue, May 6 2008 at 8:07PM PDT
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 Tue, May 6 2008 at 8:11PM PDT
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 Tue, May 6 2008 at 8:09PM PDT
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 Thu, May 8 2008 at 6:26AM PDT
grep --color highlights the hits.

///ark

[ Reply to This | # ]

Use Safari to find things more easily in text files
Authored by: zerobatsu on Tue, May 6 2008 at 10:47PM PDT
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 Wed, May 7 2008 at 10:24AM PDT
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 Wed, May 7 2008 at 11:24AM PDT
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 Sun, May 11 2008 at 5:46PM PDT
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 | # ]