Skip to content

Commit d4a714f

Browse files
committed
Patterns: examples -> exercises
1 parent e531bbf commit d4a714f

File tree

1 file changed

+23
-8
lines changed

1 file changed

+23
-8
lines changed

docs/patterns.md

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ See ``man grep`` for more options.
5252

5353
A good file to use here is ``fil.txt`` in the ``exercises/patterns`` directory. You will also use ``newfile.txt`` and ``fil.txt`` in the same directory.
5454

55+
In the following examples/exercises replace the string ``FILE`` with the file name (single search) or the path to the
56+
folder (recursive search).
57+
5558
!!! Example "Find the pattern 'word' in FILE"
5659

5760
```bash
@@ -72,19 +75,25 @@ See ``man grep`` for more options.
7275

7376
![grep string](images/grepstring.png){: style="width: 400px;float: right;padding: 3px;}
7477
75-
!!! Example "Find the instances of the word 'string' in file.txt and count them"
78+
!!! Exercise "Search for instances of the word 'string' in file.txt and count them"
79+
80+
??? Solution "Click to reveal solution"
7681

7782
```bash
7883
grep -o -i string file.txt | wc -l
7984
```
8085

81-
!!! Example "Find the lines with instances of 'string' in file.txt and output them to file.out"
86+
!!! Exercise "Search for the lines with instances of 'string' in file.txt and output them to file.out"
87+
88+
??? Solution "Click to reveal solution"
8289

8390
```bash
8491
grep string file.txt > file.out
8592
```
8693

87-
!!! Example "Find the lines with instances of 'string' in file.txt and append them to file.out"
94+
!!! Exercise "Search for the lines with instances of 'string' in file.txt and append them to file.out"
95+
96+
??? Solution "Click to reveal solution"
8897

8998
```bash
9099
grep string file.txt >> file.out
@@ -115,19 +124,23 @@ find [path] [options] [expression]
115124

116125
For more options, check ``man find``
117126

118-
**Examples**
127+
**Exercises**
119128

120129
!!! tip "Try yourself"
121130

122131
You could do the searches inside ``exercises`` directory or inside ``exercises/patterns`` directory.
123132

124-
1. Find the file ``myfile.txt`` in the directory you are standing in and below:
133+
!!! Exercise "Find the file ``myfile.txt`` in the directory you are standing in and below"
134+
135+
??? Solution "Click to reveal solution"
125136

126137
```bash
127138
find . -type f -name "file.txt"
128139
```
129140

130-
2. Find the files ``myfile.txt`` as part of the name in the directory ``expressions/patterns`` while standing in ``exercises/script``
141+
!!! "Find the files ``myfile.txt`` as part of the name in the directory ``expressions/patterns`` while standing in ``exercises/script``"
142+
143+
??? Solution "Click to reveal solution"
131144

132145
```bash
133146
find ../patterns/ -type f -name "myfile0.txt"
@@ -161,13 +174,15 @@ Some common examples of regular expressions:
161174
- **|** This wildcard makes a logical OR relationship between wildcards. You can thus search something or something else. You may need to add a '\' before this command to avoid the shell thinking you want a pipe.
162175
- **[^]** This is the equivalent of [!] in standard wildcards, i.e. it is a logical “not” and will match anything not listed within the square brackets.
163176

164-
!!! Example
177+
!!! Exercise "Search the file myfile for lines starting with an "s" and ending with an "n", and prints them to the standard output"
178+
179+
??? Solution "Click to reveal solution"
165180

166181
```bash
167182
$ cat myfile | grep '^s.*n$'
168183
```
169184

170-
This command searches the file myfile for lines starting with an "s" and ending with an "n", and prints them to the standard output.
185+
171186

172187
!!! note "Keypoints"
173188

0 commit comments

Comments
 (0)