Grep Command in Linux

Grep Command
The Grep command can find or search a regular expression or a string in a text file. To demonstrate this, let’s create a text file welcome.txt and add some content as shown.
Welcome to Linux !
Linux is a free and opensource Operating system that is mostly used by
developers and in production servers for hosting crucial components such as web
and database servers. Linux has also made a name for itself in PCs.
Beginners looking to experiment with Linux can get started with friendlier linux
distributions such as Ubuntu, Mint, Fedora and Elementary OS.
Great! Now we are ready to perform a few grep commands and manipulate the output to get the desired results. To search for a string in a file, run the command below Syntax
$ grep "string" file name
or
$ filename grep "string"
Example:
$ grep "Linux" welcome.txt
Output:

As you can see, grep has not only searched and matched the string “Linux” but has also printed the lines in which the string appears. If the file is located in a different file path, be sure to specify the file path as shown below
Colorizing Grep results using the --color option
If you are working on a system that doesn’t display the search string or pattern in a different color from the rest of the text, use the --color to make your results stand out. Example
$ grep --color "free and opensource" welcome.txt
Output:

