To use Grep from the command-line, you will have to type the ‘grep --help’ command in a terminal emulator or directly in the Linux console, which will output all the available options, as well various examples on how to use the tool to find a certain pattern into a file. The standard usage example given by the aforementioned command is “grep [OPTION]... PATTERN [FILE]...”
I want to see an example!
The most basic example is “grep -i 'hello world' menu.h main.c”, where “-i” is the [OPTION] “hello world” is the [PATTERN] and “menu.h” and “menu.c” are the [FILE]. This simple command is used for searching for the “hello world” pattern in each of the given files. Keep in mind though, that [PATTERN] is, by default, a Basic Regular Expression (BRE).
Please note that when using the “-” symbol for the [FILE] string in the above example, Grep will automatically read the standard input. Additionally, if no [FILE] is specified at all, it will read the current directory.
Does it run on my Linux box?
Grep is considered by Linux developers worldwide an essential UNIX utility, which means that it is installed by default on almost all GNU/Linux operating systems. If for some strange reason your Linux box does not have the grep tool installed, you will be able to easily install it from the default software repositories of your distribution. Both 64-bit and 32-bit architectures are supported at this time.
Reviewed by Marius Nestor on September 10th, 2014
In a hurry? Add it to your Download Basket!
- Bug fixes:
- grep --max-count=N FILE would no longer stop reading after the Nth match. I.e., while grep would still print the correct output, it would continue reading until end of input, and hence, potentially forever. [bug introduced in grep-2.19]
- A command like echo aa|grep -E 'a(b$|c$)' would mistakenly report the input as a matched line. [bug introduced in grep-2.19]
Application descriptionGrep is an open source command-line sofware that searches one or more input files for lines containing a match to a sp...