Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use regular expression to search specific package in software source? [Ubuntu]

Tags:

regex

ubuntu

Ubuntu 14.04 LTS

I know traditional approach is using sudo apt-cache search, but this command isn't best method. For example, if i want to search numpy, it will show many irrelevant packages just like following. I need to search one by one, is there better method?

.....
python3-tables-dbg - hierarchical database for Python 3 based on HDF5 (debug extension)
python3-tables-lib - hierarchical database for Python3 based on HDF5 (extension)
reinteract - Worksheet-based graphical Python shell
stimfit - Program for viewing and analyzing electrophysiological data
stimfit-dbg - Debug symbols for stimfit
texlive-lang-italian - TeX Live: Italian
python-spyderlib-doc - python IDE for scientists (Documentation)
python3-spyderlib - python IDE for scientists (Python 3)
spyder-common - python IDE for scientists (common files)
......
like image 893
hjklemacs Avatar asked Aug 15 '16 12:08

hjklemacs


People also ask

How do I search for a package in Ubuntu?

In Ubuntu and Debian systems, you can search for any package just by a keyword related to its name or description through the apt-cache search. The output returns you with a list of packages matching your searched keyword. Once you find the exact package name, you can then use it with the apt install for installation.

How do you find something in a regular expression?

Asterisk (* ): it matches zero or more occurrences of the preceding character/regular expression: qw*e will match the strings qe, qwe, qwwe but not the string qre. Backslash (\ ): it escapes special characters, for example, to search for a period: q\. e will match the string q.e but not the strings qre, qee, qe or qwwe.

How do I search for packages with apt?

To find out the package name and with it description before installing, use the 'search' flag. Using “search” with apt-cache will display a list of matched packages with short description. Let's say you would like to find out description of package 'vsftpd', then command would be.

Can you use regex with grep?

Grep Regular Expression A regular expression or regex is a pattern that matches a set of strings. A pattern consists of operators, constructs literal characters, and meta-characters, which have special meaning. GNU grep supports three regular expression syntaxes, Basic, Extended, and Perl-compatible.


1 Answers

apt-cache search searches the package name and description for the given regex pattern, you can make the Regex pattern more robust and search only on the package names by --names-only option:

apt-cache search --names-only '^python3?-numpy'

Also you don't need sudo to run apt-cache.

  • ^python3?-numpy matches package names begin with python3-numpy or python-numpy

  • If you want to search only on the python3 packages, use ^python3-numpy

  • To just get the package names:

    apt-cache search --names-only '^python3?-numpy' | awk '{print $1}'
    

Example:

$ apt-cache search --names-only '^python3?-numpy'
python-numpy - Numerical Python adds a fast array facility to the Python language
python-numpy-dbg - Fast array facility to the Python language (debug extension)
python-numpy-doc - NumPy documentation
python3-numpy - Fast array facility to the Python 3 language
python3-numpy-dbg - Fast array facility to the Python 3 language (debug extension)
python-numpydoc - Sphinx extension to support docstrings in Numpy format

$ apt-cache search --names-only '^python3?-numpy' | awk '{print $1}'
python-numpy
python-numpy-dbg
python-numpy-doc
python3-numpy
python3-numpy-dbg
python-numpydoc
like image 55
heemayl Avatar answered Oct 17 '22 06:10

heemayl