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
In this stage, you'll add support for searching the contents of multiple files.
2
2
3
-
## Searching multiple files
3
+
###Searching Multiple Files
4
4
5
-
When searching multiple files, `grep` processes each file individually and prints all matching lines to stdout with a `<filename>:` prefix. Example usage:
5
+
When searching multiple files, `grep` processes each file individually:
6
6
7
7
```bash
8
8
# This prints any lines that match search_pattern from multiple files
@@ -11,19 +11,21 @@ file1.txt:This is a line that matches search_pattern
11
11
file2.txt:Another line that matches search_pattern
12
12
```
13
13
14
-
Matching lines are printed to stdout with filename prefixes.
14
+
This behavior is similar to searching a single file, but with a few differences:
15
15
16
-
If any matching lines were found, grep exits with status code 0 (i.e. "success"). If no matching lines were found, grep exits with status code 1.
16
+
- All matching lines are printed to stdout with a `<filename>:` prefix.
17
+
- The program exits with code `0` if any matching lines were found across all files.
18
+
- The program exits with code `1` if no matching lines were found in any file.
17
19
18
-
## Tests
20
+
###Tests
19
21
20
-
The tester will create some test files and then execute multiple commands to find matches in those files. For example:
22
+
The tester will create test files and search them using your program:
21
23
22
24
```bash
23
25
# Create test files
24
26
$ echo"banana"> fruits.txt
25
27
$ echo"blueberry">> fruits.txt
26
-
$ echo"broccoli">> vegetables.txt
28
+
$ echo"broccoli"> vegetables.txt
27
29
$ echo"carrot">> vegetables.txt
28
30
29
31
# This must print the matched lines to stdout and exit with code 0
The tester will verify that all matching lines are printed to stdout. It'll also verify that the exit code is 0 if there are matching lines, and 1 if there aren't.
41
+
It will then verify that:
42
+
43
+
- All matching lines are printed to stdout with filename prefixes.
44
+
- The exit code is `0` if there are matching lines in any file.
45
+
- The exit code is `1` if there are no matching lines in any file.
0 commit comments