Explain Regular Expressions and Grep
Regular Expressions are used to search for data having a particular pattern. Some of the commands used with Regular Patterns are: tr, sed, vi and grep.
Some of the common symbols used in Regular Expressions are:
. Match any character
^ Match the beginning of the String
$ Match the end of the String
* Match zero or more characters
Represents special characters
? Match exactly one character
Suppose the content of a file is as follows:
list contect - linux interview questions - madanswer.com/linux
If you want to list the entries that start with the character ‘a’, then the command would be:
$ cat linux.txt | grep ^a
grep a - - linux interview questions - madanswer.com/linux
If you want to list the entries that start has the character ‘n’, then the command would be:
$ cat linux.txt | grep n
grep n - linux interview questions - madanswer.com/linux
25