fertresume.blogg.se

Grep vs.egrep
Grep vs.egrep













There are eleven characters with special meanings: the opening and closing square brackets, the backslash \, the caret ^, the dollar sign $, the period or dot. More Regular ExpressionsĪ regular expression can be thought of as wildcards on steroids. Use egrep to extract from the /etc/passwd file account lines containing lp or your own user id.Įxercise solutions can be found at the end of this article.Find the IP Address of the server which is stored in the file /etc/hosts.Hint: use the command grep with $(hostname).Again, confirm the contents of the file npeople by listing the file.Now append all lines where the text ends with the string 500 in the file people to the file npeople.Hint: use the command grep with >.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.















Grep vs.egrep