
The grep can also be used to search and filter within individual files or multiple files. Using the –i option is a good habit of getting into, unless of course you are trying to nail down a more specific search. Second, we piped that output to grep –i python, which simple states “go to grep and filter out and return everything with ‘python’ in it.” The –i option is there to ignore-case, as grep is case-sensitive. Ii python-pam 0.4.2-12.2ubuntu4 A Python interface to the PAM libraryįirst, we ran dpkg –l, which lists installed *.deb packages on your system. Ii python-openssl 0.12-1ubuntu2.1 Python wrapper around the OpenSSL library Ii python2.7-minimal 2.7.3-0ubuntu3.4 Minimal subset of the Python language (version 2.7) Simply run this command: # dpkg –l | grep –i python Sample Output ii python2.7 2.7.3-0ubuntu3.4 Interactive high-level object-oriented language (version 2.7) You have been scouring the web looking for tutorials, but you see that there are two different versions of Python in use, and you don’t know which one was installed on your system by the Ubuntu installer, or if it installed any modules. Let’s say that you have just installed a fresh copy of the new Ubuntu on your machine, and that you are going to give Python scripting a shot. I have found that the easiest way to get your feet wet with grep is to just dive right in and use some real world examples.
Grep syntax install#
$ sudo apt-get install grep #Debian/Ubuntu $ sudo yum install grep #RHEL/CentOS/Fedora If, for whatever reason, it is not installed on your system, you can easily install it via your package manager ( apt-get on Debian/ Ubuntu and yum on RHEL/ CentOS/ Fedora). Grep is a powerful file pattern searcher that comes equipped on every distribution of Linux. Have you ever been confronted with the task of looking for a particular string or pattern in a file, yet have no idea where to start looking? Well then, here is grep to the rescue! Intervals are specified by ‘ \’.12 Practical Examples of Linux grep Command ‘ \*’, ‘ \+’ and ‘ \?’ are special at any point in a regular expression except:

Bracket expressions where the range is backward, for example ‘ ’, are invalid. Indicates that the regular expression should match zero or one occurrence of the previous atom or regexp.īracket expressions are used to match ranges of characters.

Indicates that the regular expression should match one or more occurrences of the previous atom or regexp.

Next: posix-awk regular expression syntax, Previous: gnu-awk regular expression syntax, Up: Regular Expressions
