FAST Is A Geeky Command-Line Database

Instead of bloating his system with a fancy information gathering tool, reader Scott decided to take it really old-school—he created a batch file database to store frequently accessed information.

Using Scott's database works much the same as our founding editor's Todo.txt command-line utility—except this one is geared at storing and retrieving tiny bits of information, so it only has two actions: add or search.

You'll start out by creating a new batch file named f.bat using the following script, adjusting the path to the notes.txt file to the location on your system—you can even store the whole thing on a flash drive that can be easily carried around from system to system.

@echo off if (%1)==(-add) goto add if not (%1)==() goto find goto end

:ADD echo %2 >> F:notes.txt echo ok goto end

:FIND find /i "%1" F:notes.txt goto end

:USAGE echo USAGE: f keyword echo f -add "some string of data" goto end

:END

Once you've got that all hooked up, you can add new entries to the list with the -add parameter:

f -add "My pizza place number: 703-555-8888"

Once you've added your data to the file, you can search for it later by simply typing:

f pizza

If you really wanted to get geeky with it, you could hook the batch file into Launchy to add new entries quickly on the fly, and add a Pause command into the :FIND block so it wouldn't disappear right away—so you can easily lookup notes, phone numbers, or anything you want to store in no time flat. Great job, Scott!

FAST Command-Line Database [rad89.com]


Comments

    I did some changes to it, it still does find and add as FAST, also support to delete,update(which is slow) and maybe find via regular expressions.
    Save it as f.bat and put it in the root of your thumb drive. If you have CodySafe/PortableApplication installed, get ‘command prompt portable’ so when you launch it you are already in the root of your thumb drive and ready to type f.

    @echo off
    set VERSION=cmd database FASTx 42 based on FAST rad89.com
    set DATABASEFILE=dbname.db
    set DATABASE=.\dbpath\%DATABASEFILE%
    set TEMPDB=.\dbpath\tempdb.db
    set BACKUPDB=.\dbpath\backupdb.db

    color a
    if (%1)==(-add) goto add
    if (%1)==(-del) goto checkdelete
    if (%1)==(-ls) goto listall
    if (%1)==(-h) goto usage
    if (%1)==(-notepad) goto notepad
    if (%1)==(-update) goto updatecheck1
    if (%1)==(-or) goto checkorfind
    if (%1)==(-backup) goto backup
    if not (%1)==() goto find
    if (%1)==() goto usage
    goto end

    :ADD
    echo %2 [%date% - %time%] >> "%DATABASE%"
    echo done [%date% - %time%]
    goto end

    rem with /I not case sensitive
    :FIND
    findstr /R /N /I /C:%1 "%DATABASE%"
    goto end

    :CHECKORFIND
    if not (%2)==() goto orfind
    echo missing argument
    echo %0 -or "str1 str2 str3" to find either words in a string
    goto end
    :ORFIND
    findstr /R /N /I %2 %DATABASE%
    goto end

    :LISTALL
    findstr /R /N . "%DATABASE%"
    goto end

    :NOTEPAD
    start notepad "%DATABASE%"
    goto end

    :BACKUP
    copy "%DATABASE%" "%BACKUPDB%"
    echo backup ok.
    goto end

    rem ============
    :CHECKDELETE
    if not (%2)==() goto confirmdelete
    echo nothing to delete
    echo %0 -del "string" to delete lines match full string
    echo %0 to show usage
    goto end

    :CONFIRMDELETE
    echo ----------lines fully match [%2]:
    findstr /N /I /C:%2 "%DATABASE%"
    set /p run=Do you want to delete these lines? [YES / NO]
    if not %run% == YES goto nodelete
    findstr /V /I /C:%2 "%DATABASE%" >> "%TEMPDB%"
    del /q "%DATABASE%"
    rename "%TEMPDB%" "%DATABASEFILE%"
    echo ----------lines contains [%2] deleted.
    goto end

    :NODELETE
    echo nothing deleted
    goto end

    rem ===============
    :UPDATECHECK1
    if not (%2)==() goto updatecheck2
    echo no OLD_STRING given
    echo %0 -update old_str new_str update lines,full match old_str
    echo %0 to show usage
    goto end
    :UPDATECHECK2
    if not (%3)==() goto doupdate
    echo no NEW_STRING given
    echo %0 -update old_str new_str update lines,full match old_str
    echo %0 to show usage
    goto end

    :DOUPDATE
    echo ----------lines fully match [%2]:
    findstr /N /I /C:%2 "%DATABASE%"
    set /p run=Do you want to delete these lines and insert %3? [YES / NO]
    if not %run% == YES goto noupdate
    for /f "delims=" %%i in ('type %DATABASE%') do (
    echo %%i|>nul 2>nul findstr /I /c:%2&&(>>%TEMPDB% echo %3 [%date% - %time%])||(>>%TEMPDB% echo %%i)
    )
    del /q "%DATABASE%"
    rename "%TEMPDB%" "%DATABASEFILE%"
    goto end

    :NOUPDATE
    echo noting updated
    goto end

    :USAGE
    echo ---%VERSION%---
    echo USAGE: %0 "string" find string(support regular expressions maybe)
    echo %0 . or %0 -ls "list all entries"
    echo %0 -add "string to add to the db"
    echo %0 -del "string" to delete lines match the full string
    echo %0 -notepad to open the file in notepad
    echo %0 -update old_str new_str delete old lines fully match old_str,insert new_str
    echo %0 -or "str1 str2 str3" find lines match either of these words
    echo %0 -backup to backup the database
    echo %0 -h to show this usage
    goto end
    rem http://twitter.com/Godsibb
    :END

    ..and then I jizzed in my pants

Join the discussion!

Trending Stories Right Now