The ^ matches the expression in the beginning of a line, only if it is the first character in a regular expression. Nov 10 13:25:46 gs123 ntpd: synchronized to LOCAL(0), stratum 10 Nov 10 01:17:17 gs123 ntpd: synchronized to LOCAL(0), stratum 10 i.e All the messages logged on November 10. In the following example, it displays all the line which starts with the Nov 10. In grep command, caret Symbol ^ matches the expression at the start of a line. Let us take the file /var/log/messages file which will be used in our examples.
The future part 2 article will cover advanced regular expression examples in grep. This part 1 article covers grep examples for simple regular expressions. This articles is part of a 2 article series. Regular expressions search for the patterns on each line of the file. You can also use regular expressions with grep command when you want to search for a text containing a particular pattern. Please refer our earlier article for 15 practical grep command examples. Grep command is used to search for a specific string in a file. Most of the Linux commands and programming languages use regular expression. Regular expressions are used to search and manipulate the text, based on the patterns.