The asterisk

The asterisk is used to match the existence of a character or a character class zero or more times.

This can be useful when searching for a word with multiple variations or that has been misspelled:

$ echo "Checking colors" | awk '/colou*rs/{print $0}'$ echo "Checking colours" | awk '/colou*rs/{print $0}'

If the character u doesn't exist at all or exists, that will match the pattern.

We can benefit from the asterisk character by using it with the dot character to match any number of characters.

Let's see how to use them against the following example file:

This is a sample lineAnd this is another oneThis is one moreFinally, the ...

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.