You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/patterns.md
+23-8Lines changed: 23 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -52,6 +52,9 @@ See ``man grep`` for more options.
52
52
53
53
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.
54
54
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
+
55
58
!!! Example "Find the pattern 'word' in FILE"
56
59
57
60
```bash
@@ -72,19 +75,25 @@ See ``man grep`` for more options.
You could do the searches inside ``exercises`` directory or inside ``exercises/patterns`` directory.
123
132
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"
125
136
126
137
```bash
127
138
find . -type f -name "file.txt"
128
139
```
129
140
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"
131
144
132
145
```bash
133
146
find ../patterns/ -type f -name "myfile0.txt"
@@ -161,13 +174,15 @@ Some common examples of regular expressions:
161
174
-**|** 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.
162
175
-**[^]** 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.
163
176
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"
165
180
166
181
```bash
167
182
$ cat myfile | grep '^s.*n$'
168
183
```
169
184
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.
0 commit comments