From 53dec51c7ed28860e667d96dc4cdf5c5e48dd9eb Mon Sep 17 00:00:00 2001 From: waldek Date: Mon, 9 May 2022 17:51:12 +0200 Subject: [PATCH] adds basic grep --- essential/readme.md | 46 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/essential/readme.md b/essential/readme.md index b937e52..b2bf8a6 100644 --- a/essential/readme.md +++ b/essential/readme.md @@ -1545,6 +1545,7 @@ This being said, you can use `grep` without regular expressions as well and this Most distributions will come with some dictionaries installed. We can find the American one with the `locate` command. +The *third* one in line is the one we need, but have a look at the other files if you're intrigued. ``` waldek@debian:~$ locate american @@ -1581,6 +1582,51 @@ waldek@debian:~$ locate american /var/lib/ispell/american.remove ``` +We can use `grep` to find all occurrences of the word *hippo* with the following syntax. + +``` +waldek@debian:~$ grep "hippop" /usr/share/dict/american-english +hippopotami +hippopotamus +hippopotamus's +hippopotamuses +waldek@debian:~$ +``` + +We can search for multiple patterns with the `|` character **but** this charater has a special meaning in the shell so we need to escape it with a `\` **or** we can use *extended* `grep` with either `egrep` or `grep -E`. + +``` +waldek@debian:~$ grep "hippo\|tamu" /usr/share/dict/american-english +Metamucil +Metamucil's +hippo +hippo's +hippopotami +hippopotamus +hippopotamus's +hippopotamuses +hippos +whippoorwill +whippoorwill's +whippoorwills +waldek@debian:~$ grep -E "hippo|tamu" /usr/share/dict/american-english +Metamucil +Metamucil's +hippo +hippo's +hippopotami +hippopotamus +hippopotamus's +hippopotamuses +hippos +whippoorwill +whippoorwill's +whippoorwills +waldek@debian:~$ +``` + +Adding the `--color` argument to `grep will make the matched patterns jump out with a color, depending on the color scheme of your terminal. + ## Wildcards and regular expressions # Exercise