

More Regular ExpressionsĪ regular expression can be thought of as wildcards on steroids.

Confirm the contents of the file npeople by listing the file.Create a new file, npeople, containing all lines beginning with the string Personal in the people file.Hint: use the command grep with >.Find all lines containing the string Smith in the file people.Hint: use the command grep but remember that by default, it is case sensitive.Display the file people and examine its contents.To find all lines starting with text using the ^ character: Note that the *, which may be used at the command line to match any number of characters including none, is not used in the same way here.Īlso note the use of quotes in the following examples. Preceding a symbol makes it a literal character The special characters available include: ^

Note that the strings may need to be enclosed in quotes. A regular expression is a character string that includes special characters to allow pattern matching within utilities such as grep, vim and sed. The command grep may also be used with regular expressions by using one or more of eleven special characters or symbols to refine the search. Find the entry for your login in the /etc/passwdĮxercise solutions can be found at the end of this article.Find how many lines do NOT contain the text var.Find how many lines in the file contain the text.Now find all occurrences of the text var in the file /etc/passwd.
