|
|
one-line perl version
the above one line perl code locates the phrase "centimeter measure" using the same approach as the python script. You can make an alias out of this. It will goof up if your phrase has an unescaped double-quotation mark in it. Note that it overwrites a temporary file called /tmp/crap when it runs. I had to create that temporary file because the silly behavior of mdimport does not write to a standard stream that is easy to capture.
one-line perl version
A couple of usage notes:
1) it's hardcoded to look in ~/ your home directory. This could obviously be changed to be an input parameter as well 2) don't forget to quote your phrase. 3) the script is multi-threaded, doing the mdfind and mdimport concurrenty. This flourish however is overhill in many cases because the slow step in the process is the MDimport. 4) it hunts the phrase you are seeking in all of the metadata, not just the text content. It would be easy to modify to restrict it to just the text content, but why would you want that. 5) if you want this to run lightning fast then just replace the mdimport with cat. like this:
this will not use mdimport but just do a raw text search
one-line perl version
Cat will choke on "files" that are really bundles (like mellel) and odf files which are zipped archives. Not to mention searching on the raw input of pdf files is an issue. (Doesn't seem to work for me.)
one-line perl version
well yeah the cat version is only good for plain text. But MDimport is dog slow, so when you know it's plain text. If one wanted to push things a bit one could run the files through `strings` first to remove all the binary crud and hope to get lucky finding a the phrase in a plain text file even if it was pdf or Word.doc format. It's so much faster than Mdimport that one could just do it as a pre-screen.
one-line perl version
By the way, did you figure out what the heck is up with mdimport's output streams? It seems to be own of those crazy functions like top that can tell if it's being run in a terminal or redirected to a file or sent on a pipe, and then changes which stream it uses to to write the data. For example if you try to capture it's output using backtics in perl it still writes to the terminal directly, but if to redirect it to a file it does not write to the terminal. |
SearchFrom our Sponsor...Latest Mountain Lion HintsWhat's New:HintsNo new hintsComments last 2 daysNo new commentsLinks last 2 weeksNo recent new linksWhat's New in the Forums?
Hints by TopicNews from Macworld
From Our Sponsors |
|
Copyright © 2014 IDG Consumer & SMB (Privacy Policy) Contact Us All trademarks and copyrights on this page are owned by their respective owners. |
Visit other IDG sites: |
|
|
|
Created this page in 0.08 seconds |
|