Anchor characters

Anchor characters are used to match the beginning or the end of a line. There are two anchor characters: the caret (^) and the dollar sign ($).

The caret character is used to match the beginning of a line:

$ echo "Welcome to shell scripting" | awk '/^Welcome/{print $0}'$ echo "SHELL scripting" | awk '/^Welcome/{print $0}'$ echo "Welcome to shell scripting" | sed -n '/^Welcome/p'

So, the caret character is used to check whether the specified text is at the beginning of the line.

If you want to search for the caret as a character, you should escape it with a backslash if you use AWK.

However, if you use sed, you don't need ...

Get Mastering Linux Shell Scripting now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.