Results 1 to 9 of 9

Thread: Linux/Unix commands for seraching database

  1. #1
    Join Date
    Apr 2006
    Beans
    2,612

    Linux/Unix commands for seraching database

    Hi all,

    Which Linux/Unix command lines shall I use to search files containing words/phrase on database ?
    grep/find/locate ?

    Example:
    words - English/French/Chinese
    phrases - speech to words/words to speech
    etc.

    Thanks in advance

    Regards
    satimis
    Last edited by satimis; December 13th, 2019 at 04:33 AM.

  2. #2
    Join Date
    Nov 2008
    Location
    Magdalena,New Mexico,USA
    Beans
    Hidden!
    Distro
    Ubuntu Mate Development Release

    Re: Linux/Unix commands for seraching database

    grep would certainly do it

    maybe awk ???
    http://linuxcommand.org/lc3_adv_awk.php
    Registered Linux User # 529389
    Arch Linux, MX 18.3 Linux
    my personal web page http://users.gilanet.com/~tfrost
    "If you're not living on the edge, you're taking up too much space"--Unknown

  3. #3
    Join Date
    Nov 2008
    Location
    Metro Boston
    Beans
    14,701
    Distro
    Kubuntu Development Release

    Re: Linux/Unix commands for seraching database

    What kind of "database?" If it's an SQL system like MySQL or PostgreSQL, you'd need to use the native client for those systems and write a query in SQL. Something like
    Code:
    select * from tablename where field='someword';
    That's the most basic type of matching. You can use wildcards like % ('%someword%') or comparisons using regular expressions.

    I don't how to search a Berkeley DB database since I never use them.

    You can use the client in a command like this (using the psql client for Postgres):
    Code:
    psql -c "select * from tablename where field='someword'" databasename
    Last edited by SeijiSensei; December 13th, 2019 at 04:58 PM.
    If you ask for help, do not abandon your request. Please have the courtesy to check for responses and thank the people who helped you.

    Blog · Linode System Administration Guides · Android Apps for Ubuntu Users

  4. #4
    Join Date
    Apr 2006
    Beans
    2,612

    Re: Linux/Unix commands for seraching database

    Quote Originally Posted by SeijiSensei View Post
    What kind of "database?" If it's an SQL system like MySQL or PostgreSQL, you'd need to use the native client for those systems and write a query in SQL. - deleted
    Oh sorry.

    I meant my hard drives.

    I have 2 hard drives on the PC
    Drive-1 for running OS
    Drive-2 for storage

    Regards
    satimis

  5. #5
    Join Date
    Mar 2010
    Location
    Squidbilly-Land
    Beans
    Hidden!
    Distro
    Ubuntu Mate 16.04 Xenial Xerus

    Re: Linux/Unix commands for seraching database

    You can load a search tool, like recoll, point the index engine at the directories you want indexed then use the GUI search to ... er ... search.

    For filenames, I use locate -i.
    For stuff inside files in 1 directory, I use egrep ... like
    Code:
    cd ~/bin/
    egrep convert *sh
    For random searches where I don't know the filename, part of the filename or specific spelling of the words, I'll use recoll.

    recoll has a thick client and a CLI version. I use both, just depends.

    There are a number of similar tools to recoll - beagle? I've never used them. Recoll has the soundex engine, so it can find stuff based on what the works sound-like, not just spelling. It also deals with different suffixes. Recoll indexing can take a while and the index files get large. I refresh the index weekly. Example recoll CLI:
    Code:
    recoll -b -t -q "$1"
    locate needs to be pre-indexed too. updatedb is the tool for that. By default it ignores anything in /media/ and /mnt/, so if you want to index stuff there, config changes are necessary.

    Lots-o-methods. Each has a place.

  6. #6
    Join Date
    Aug 2011
    Location
    51.8° N 5.8° E
    Beans
    4,892
    Distro
    Xubuntu 19.10 Eoan Ermine

    Re: Linux/Unix commands for seraching database

    Of course, you can only search for text in files with a file format understood by the search tool. Plain text is easy, but if you design your own binary format, you'll have to write your own search tool (or at least some sort of filter).

  7. #7
    Join Date
    Mar 2011
    Location
    U.K.
    Beans
    Hidden!
    Distro
    Ubuntu 18.04 Bionic Beaver

    Re: Linux/Unix commands for seraching database

    ripgrep is a useful tool which can also search multiple file types.

  8. #8
    Join Date
    Apr 2006
    Beans
    2,612

    Re: Linux/Unix commands for seraching database

    Quote Originally Posted by TheFu View Post
    - snip -
    For random searches where I don't know the filename, part of the filename or specific spelling of the words, I'll use recoll.

    recoll has a thick client and a CLI version. I use both, just depends.

    There are a number of similar tools to recoll - beagle? I've never used them. Recoll has the soundex engine, so it can find stuff based on what the works sound-like, not just spelling. It also deals with different suffixes. Recoll indexing can take a while and the index files get large. I refresh the index weekly. Example recoll CLI:
    Code:
    recoll -b -t -q "$1"
    - snip -
    Thanks for your advice.

    I expect to find the filename which contains a phrase
    Code:
    french to english
    Performed following steps

    $ sudo updatedb

    $ recoll -b -t -q "french to english"
    Code:
    :3:common/rclinit.cpp:308::Configuration directory: /home/satimis/.recoll
    :2:rcldb/rcldb.cpp:875::Db::open: exception while opening [/home/satimis/.recoll/xapiandb]: Couldn't stat '/home/satimis/.recoll/xapiandb'
    Cant open database in /home/satimis/.recoll/xapiandb reason: Couldn't stat '/home/satimis/.recoll/xapiandb'
    $ recoll -b -t -q "french"
    Code:
    :3:common/rclinit.cpp:308::Configuration directory: /home/satimis/.recoll
    :2:rcldb/rcldb.cpp:875::Db::open: exception while opening [/home/satimis/.recoll/xapiandb]: Couldn't stat '/home/satimis/.recoll/xapiandb'
    Cant open database in /home/satimis/.recoll/xapiandb reason: Couldn't stat '/home/satimis/.recoll/xapiandb'
    same result

    Regards
    satimis

  9. #9
    Join Date
    Mar 2010
    Location
    Squidbilly-Land
    Beans
    Hidden!
    Distro
    Ubuntu Mate 16.04 Xenial Xerus

    Re: Linux/Unix commands for seraching database

    updatedb is for locate. Nothing else. Locate only looks at filenames. Nothing else and it only lets the user see filenames that userid is allowed to see.

    recoll needs to be run first, configured, then run in index mode before you can search using it. It is looking for a set of index files in '/home/satimis/.recoll/xapiandb'. There are a few how-to articles on using recoll if the manpage isn't sufficient.

    Don't assume there is a single space between each word or that the words are on the same lines. I would use the longest, most unique word to do a case insensitive search to get close.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •