Skip to content

Commit e794be3

Browse files
authored
Merge pull request #160 from codecrafters-io/TropicolX-patch-4
Revise "Search multiple files #is6" (stage 18)
2 parents 8c0f76a + 55744f7 commit e794be3

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed
Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
In this stage, you'll add support for searching the contents of multiple files.
22

3-
## Searching multiple files
3+
### Searching Multiple Files
44

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:
66

77
```bash
88
# 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
1111
file2.txt:Another line that matches search_pattern
1212
```
1313

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:
1515

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.
1719

18-
## Tests
20+
### Tests
1921

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:
2123

2224
```bash
2325
# Create test files
2426
$ echo "banana" > fruits.txt
2527
$ echo "blueberry" >> fruits.txt
26-
$ echo "broccoli" >> vegetables.txt
28+
$ echo "broccoli" > vegetables.txt
2729
$ echo "carrot" >> vegetables.txt
2830

2931
# This must print the matched lines to stdout and exit with code 0
@@ -36,4 +38,8 @@ vegetables.txt:broccoli
3638
$ ./your_program.sh -E "missing_fruit" fruits.txt vegetables.txt
3739
```
3840

39-
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

Comments
 (0)