Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I take daily notes in a plaintext file labeled with date in the YYYYMMDD format. These files are no more than 100 lines long, and are written in a blog style format.

I'd like to be able search these files as if they were blog posts indexed by google, with some phrase query returning the most relevant/recent date filenames, with a snippet containing the relevant part.

Ideally it would be something like this:

#searchindex "laptop no sound"

returns:

20100909.txt:

... laptop sound isn't working...

20100101.txt

... sound is too loud... debating what laptop to buy...

and so on and so forth.

I'm working on a linux platform (Debian with GNOME). I've looked at beagle and tracker, but they just seem complete overkill for what I want.

EDIT: Many suggestions include grep, but I would like something a little more powerful than that, taking into account proximity of keywords, date, etc. Many of these files will have somewhat similar keywords, so I'll be getting too many hits using just grep. I don't mind the extra overhead of indexing.

share|improve this question
add comment

4 Answers

up vote 2 down vote accepted

You can use grep in a bash function for that:

function searchindex ()
{
    if [ "$#" -gt 0 ] ; then
        ls -t | xargs -L1 grep -H -C3 -- `echo "$@" | sed 's/ /\\\|/g'`
    fi
}

Where -C3 is the number of lines of the context, if you want just the matched line you can remove it.

share|improve this answer
add comment

Another option is to use glimpse.

It is an indexer, so you first have to build the index:

glimpseindex -B -H {Directory for index} -f

You can search the files then in a rather powerful way with the glimpse command.

Glimpse is rather old, but it does the job for me.

share|improve this answer
add comment

Would a plain grep do what you want?

$ egrep "laptop|sound" *txt
20100101.txt:sound is too loud... debating what laptop to buy
20100505.txt:the sound of silence
20100606.txt:I just bought a new laptop
20100909.txt:laptop sound isn't working

$ egrep "laptop.*sound|sound.*laptop" *txt
20100101.txt:sound is too loud... debating what laptop to buy
20100909.txt:laptop sound isn't working

$ grep laptop *txt | grep sound
20100101.txt:sound is too loud... debating what laptop to buy
20100909.txt:laptop sound isn't working
share|improve this answer
add comment

Google-Desktop-Linux is available in the Debian repositories and will do what you want. If you have trouble with the default hotkey to bring up the search box then use this fix. You can restrict the types of files and locations that are indexed so you don't get overloaded. I tried both Beagle and Tracker before settling on Google Desktop.

Sorry-not command line, but still worth a look.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.