From de7f8c3e97f5ec362a547d6998c79c5183d6feb5 Mon Sep 17 00:00:00 2001 From: Udeshya Dhungana <075bct095.udeshya@pcampus.edu.np> Date: Wed, 12 Nov 2025 12:15:43 +0545 Subject: [PATCH 1/9] Add stage instructions for multiple matches --- .gitignore | 3 ++ course-definition.yml | 43 +++++++++++++++++ stage_descriptions/multiple-matches-01-ge4.md | 36 ++++++++++++++ stage_descriptions/multiple-matches-02-ru8.md | 30 ++++++++++++ stage_descriptions/multiple-matches-03-cy4.md | 37 ++++++++++++++ stage_descriptions/multiple-matches-04-vq9.md | 36 ++++++++++++++ stage_descriptions/multiple-matches-05-ss2.md | 48 +++++++++++++++++++ 7 files changed, 233 insertions(+) create mode 100644 stage_descriptions/multiple-matches-01-ge4.md create mode 100644 stage_descriptions/multiple-matches-02-ru8.md create mode 100644 stage_descriptions/multiple-matches-03-cy4.md create mode 100644 stage_descriptions/multiple-matches-04-vq9.md create mode 100644 stage_descriptions/multiple-matches-05-ss2.md diff --git a/.gitignore b/.gitignore index 132c5ef4..ca811343 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,5 @@ course-definition-tester .history/ + +# MacOS +.DS_Store \ No newline at end of file diff --git a/course-definition.yml b/course-definition.yml index 8a9cd428..37e5a2bd 100644 --- a/course-definition.yml +++ b/course-definition.yml @@ -76,6 +76,13 @@ extensions: Along the way, you'll learn about how to implement the `*` quantifier (zero or more), and bounded quantifiers. [1]: https://learn.microsoft.com/en-us/dotnet/standard/base-types/quantifiers-in-regular-expressions + - slug: "multiple-matches" + name: "Multiple Matches" + description_markdown: | + In this challenge extension, you'll add support for printing the multiple matching results to your Grep implementation. + + Along the way, you'll learn about how to implement the `-c` flag, `-o` flag, and more. + stages: - slug: "cq2" name: "Match a literal character" @@ -304,3 +311,39 @@ stages: difficulty: hard marketing_md: |- In this stage, we'll add support for `{n,m}`, the [between n and m times](https://docs.microsoft.com/en-us/dotnet/standard/base-types/quantifiers-in-regular-expressions#match-between-n-and-m-times-nm) quantifier. + + # Multiple matches + - slug: "ge4" + primary_extension_slug: "multiple-matches" + name: "Count matching lines" + difficulty: easy + marketing_md: |- + In this stage, you'll add support for printing the count of matching lines. + + - slug: "ru8" + primary_extension_slug: "multiple-matches" + name: "Print matching lines" + difficulty: easy + marketing_md: |- + In this stage, you'll add support for printing the matching lines. + + - slug: "cy4" + primary_extension_slug: "multiple-matches" + name: "Print line numbers" + difficulty: easy + marketing_md: |- + In this stage, you'll add support for displaying the line numbers of the matching lines. + + - slug: "vq9" + primary_extension_slug: "multiple-matches" + name: "Limit matching lines" + difficulty: medium + marketing_md: |- + In this stage, you'll add support for stopping the pattern search after a specified number of lines have been matched. + + - slug: "ss2" + primary_extension_slug: "multiple-matches" + name: "Print individual matches" + difficulty: hard + marketing_md: |- + In this stage, you'll add support for printing only the matching texts. \ No newline at end of file diff --git a/stage_descriptions/multiple-matches-01-ge4.md b/stage_descriptions/multiple-matches-01-ge4.md new file mode 100644 index 00000000..d49def2c --- /dev/null +++ b/stage_descriptions/multiple-matches-01-ge4.md @@ -0,0 +1,36 @@ +In this stage, you'll add support for printing the count of matching lines. + +### The `-c` option + +The `-c` option, also known as the count option, is used to count the number of lines which match the specified pattern. + +Example Usage: + +```bash +# Two of the three lines contain a digit +echo -e "line1\nline2\nlinethree" | grep -c -E '\d' +2 + +# Both lines contain a digit +# Even though the first line contains multiple occurences of digit, this line is counted only once +echo -e "line1text1text2\nline2 | grep -c -E '\d' +2 +``` + +### Tests + +The tester will execute your program like this: + +```bash +$ echo -e "line1\nline2\nline3" | ./your_program.sh -E "pattern" +``` + +If none of the lines match the specified pattern: + +- The exit code of the program should be `1`. +- The output of the program should be `0` + +If at least one line matches the specified pattern: + +- The exit code of the program should be `0`. +- The output of the program should be the number of lines that match the pattern. diff --git a/stage_descriptions/multiple-matches-02-ru8.md b/stage_descriptions/multiple-matches-02-ru8.md new file mode 100644 index 00000000..22d3ca9b --- /dev/null +++ b/stage_descriptions/multiple-matches-02-ru8.md @@ -0,0 +1,30 @@ +In this stage, you'll add support for printing the matching lines. + +### Printing the matching line + +If a line from the standard input is matched, grep prints all the matching lines to the standard output. + +Example usage: + +```bash +$ echo -ne "caats\ndog\ncaaaats" | grep -E "ca+ts" +caats +caaaats +``` + +### Tests + +The tester will execute your program like this: + +```bash +$ echo -ne "dogs\ndog" | ./your_program.sh -E "dogs?" +dogs +dog +``` + +If none of the lines match the specified pattern, your program must: +- Exit with the code 1 + +If at least one line matches the specified pattern, your program must: +- Exit with the code 0 +- Print all the matching lines to the standard output \ No newline at end of file diff --git a/stage_descriptions/multiple-matches-03-cy4.md b/stage_descriptions/multiple-matches-03-cy4.md new file mode 100644 index 00000000..3a54e745 --- /dev/null +++ b/stage_descriptions/multiple-matches-03-cy4.md @@ -0,0 +1,37 @@ +In this stage, you'll add support for displaying the line numbers of the matching lines. + +### The `-n` option + +The `-n` option, also known as the `line number` option, is used to display the line number of each matching line. + +Example usage: + +```bash +$ echo -ne "dogs\ncat\ndog" | grep -n -E "dogs?" +1:dogs +3:dog +``` + +The output is the line number, followed by a colon, followed by that line's text. + +### Tests + +The tester will execute your program like this: + +```bash +$ echo -e "line1\nline2\nline3" | ./your_program.sh -E "pattern" +``` + +If none of the lines match the specified pattern: + +- The exit code of your program should be 1. +- No output should be produced by the program to the standard output. + +If at least one line matches the specified pattern: + +- The exit code of your program should be 0. +- All the matching lines should be printed, each preceeded by its number and a colon separator. + +### Notes + +1. The line numbering start from 1, not 0. \ No newline at end of file diff --git a/stage_descriptions/multiple-matches-04-vq9.md b/stage_descriptions/multiple-matches-04-vq9.md new file mode 100644 index 00000000..57e73247 --- /dev/null +++ b/stage_descriptions/multiple-matches-04-vq9.md @@ -0,0 +1,36 @@ +In this stage, you'll add support for stopping the pattern search after a specified number of lines have been matched. + +### The `-m` option + +The `-m` option, also known as the `max-count` option, is used to stop the search after the specified number of lines have matched the pattern. + +Example usage: + +```bash +# Stop after 1 matching line has been found +$ echo -ne "line1_text11_text2\nline2\nline3_text33" | grep -m 1 -E '\d' +line1_text11_text2 +``` + +### Tests + +The tester will execute your program like this: + +```bash +$ echo -e "line1\nline2\nline3" | ./your_program.sh -m 1 -E "pattern" +``` + +If none of the lines match the specified pattern + +- The exit code of the program should be 1 +- No output should be printed by the program + +If at least one line matches the specified pattern: + +- The exit code of the program should be 0 +- All the matching lines should be printed +- There should not be more than the `max-count` number of lines in the output. The search should stop after encountering first `max-count` number of lines. + +### Notes + +- The tester will only test with a positive value of `max-count`. You don't need to implement the cases where the max count is zero or negative. \ No newline at end of file diff --git a/stage_descriptions/multiple-matches-05-ss2.md b/stage_descriptions/multiple-matches-05-ss2.md new file mode 100644 index 00000000..f2e72e02 --- /dev/null +++ b/stage_descriptions/multiple-matches-05-ss2.md @@ -0,0 +1,48 @@ +In this stage, you'll add support for printing only the matching texts. + +### The `-o` flag + +The `-o` flag, also known as the `only-matching` flag, is used to print only the matching texts in a separate line. + +Example usage: + +```bash +# The `\d` matches each digit separately, so each digit (if found) is printed in its own line +$ echo -ne "line1_text11_text2\nline2\nline3_text33" | grep -o -E '\d' +1 +1 +1 +2 +2 +3 +3 +3 + +# The `\d\d` matches a pair of digits, so each pair (if found) is printed in its own line +$ echo -ne "line1_text11_text2\nline2\nline3_text33" | grep -o -E '\d\d' +11 +33 + +# Each match is printed in its own line +$ echo -ne "I have 4 cows and 9 cats\nHe has 3 cats" | grep -o -E '\d (cows|cats)' +4 cows +9 cats +3 cats +``` + +### Tests +The tester will execute your program like this: + +```bash +$ echo -e "line1\nline2\nline3" | ./your_program.sh -o -E "pattern" +``` + +If none of the lines match the specified pattern, + +- Your program should exit with the code 1 +- No output should be printed + +If at least one line matches the pattern, + +- Your program should exit with the code 0 +- All the matching parts should be printed in their separate line \ No newline at end of file From 4e3e44c5163e422549e36897c344a8eb0c02918f Mon Sep 17 00:00:00 2001 From: Udeshya Dhungana <075bct095.udeshya@pcampus.edu.np> Date: Wed, 12 Nov 2025 12:22:07 +0545 Subject: [PATCH 2/9] Apply LLM suggestions --- stage_descriptions/multiple-matches-01-ge4.md | 2 +- stage_descriptions/multiple-matches-02-ru8.md | 2 +- stage_descriptions/multiple-matches-03-cy4.md | 8 ++++---- stage_descriptions/multiple-matches-04-vq9.md | 3 +-- 4 files changed, 7 insertions(+), 8 deletions(-) diff --git a/stage_descriptions/multiple-matches-01-ge4.md b/stage_descriptions/multiple-matches-01-ge4.md index d49def2c..849eea36 100644 --- a/stage_descriptions/multiple-matches-01-ge4.md +++ b/stage_descriptions/multiple-matches-01-ge4.md @@ -22,7 +22,7 @@ echo -e "line1text1text2\nline2 | grep -c -E '\d' The tester will execute your program like this: ```bash -$ echo -e "line1\nline2\nline3" | ./your_program.sh -E "pattern" +$ echo -e "line1\nline2\nline3" | ./your_program.sh -c -E "pattern" ``` If none of the lines match the specified pattern: diff --git a/stage_descriptions/multiple-matches-02-ru8.md b/stage_descriptions/multiple-matches-02-ru8.md index 22d3ca9b..33ef2c58 100644 --- a/stage_descriptions/multiple-matches-02-ru8.md +++ b/stage_descriptions/multiple-matches-02-ru8.md @@ -1,6 +1,6 @@ In this stage, you'll add support for printing the matching lines. -### Printing the matching line +### Printing the matching lines If a line from the standard input is matched, grep prints all the matching lines to the standard output. diff --git a/stage_descriptions/multiple-matches-03-cy4.md b/stage_descriptions/multiple-matches-03-cy4.md index 3a54e745..a64863b9 100644 --- a/stage_descriptions/multiple-matches-03-cy4.md +++ b/stage_descriptions/multiple-matches-03-cy4.md @@ -12,14 +12,14 @@ $ echo -ne "dogs\ncat\ndog" | grep -n -E "dogs?" 3:dog ``` -The output is the line number, followed by a colon, followed by that line's text. +When the -n option is used, the output is the line number, followed by a colon, followed by that line's text. ### Tests The tester will execute your program like this: ```bash -$ echo -e "line1\nline2\nline3" | ./your_program.sh -E "pattern" +$ echo -e "line1\nline2\nline3" | ./your_program.sh -n -E "pattern" ``` If none of the lines match the specified pattern: @@ -30,8 +30,8 @@ If none of the lines match the specified pattern: If at least one line matches the specified pattern: - The exit code of your program should be 0. -- All the matching lines should be printed, each preceeded by its number and a colon separator. +- All the matching lines should be printed, each preceded by its number and a colon separator. ### Notes -1. The line numbering start from 1, not 0. \ No newline at end of file +1. The line numbering starts from 1, not 0. \ No newline at end of file diff --git a/stage_descriptions/multiple-matches-04-vq9.md b/stage_descriptions/multiple-matches-04-vq9.md index 57e73247..e0e91500 100644 --- a/stage_descriptions/multiple-matches-04-vq9.md +++ b/stage_descriptions/multiple-matches-04-vq9.md @@ -28,8 +28,7 @@ If none of the lines match the specified pattern If at least one line matches the specified pattern: - The exit code of the program should be 0 -- All the matching lines should be printed -- There should not be more than the `max-count` number of lines in the output. The search should stop after encountering first `max-count` number of lines. +- Print matching lines until reaching the max-count; do not print more than the max-count lines ### Notes From ba3dadcb4800b1766363e23ee1bc031114caf925 Mon Sep 17 00:00:00 2001 From: Udeshya Dhungana <075bct095.udeshya@pcampus.edu.np> Date: Wed, 12 Nov 2025 12:23:55 +0545 Subject: [PATCH 3/9] Fix grammar suggestion from LLM --- stage_descriptions/multiple-matches-04-vq9.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stage_descriptions/multiple-matches-04-vq9.md b/stage_descriptions/multiple-matches-04-vq9.md index e0e91500..5b91fffd 100644 --- a/stage_descriptions/multiple-matches-04-vq9.md +++ b/stage_descriptions/multiple-matches-04-vq9.md @@ -28,7 +28,7 @@ If none of the lines match the specified pattern If at least one line matches the specified pattern: - The exit code of the program should be 0 -- Print matching lines until reaching the max-count; do not print more than the max-count lines +- Print matching lines until reaching the `max-count`. Do not print more than the `max-count` lines ### Notes From 338c9e3f17dd023c3de4edf1aa9adbb5a9507ee0 Mon Sep 17 00:00:00 2001 From: Udeshya Dhungana <075bct095.udeshya@pcampus.edu.np> Date: Fri, 14 Nov 2025 10:46:05 +0545 Subject: [PATCH 4/9] Removed unnecessary stages --- course-definition.yml | 28 -------------- stage_descriptions/multiple-matches-01-ge4.md | 36 ------------------ stage_descriptions/multiple-matches-02-ru8.md | 30 --------------- stage_descriptions/multiple-matches-03-cy4.md | 37 ------------------- stage_descriptions/multiple-matches-04-vq9.md | 35 ------------------ 5 files changed, 166 deletions(-) delete mode 100644 stage_descriptions/multiple-matches-01-ge4.md delete mode 100644 stage_descriptions/multiple-matches-02-ru8.md delete mode 100644 stage_descriptions/multiple-matches-03-cy4.md delete mode 100644 stage_descriptions/multiple-matches-04-vq9.md diff --git a/course-definition.yml b/course-definition.yml index 37e5a2bd..2eb0aa5b 100644 --- a/course-definition.yml +++ b/course-definition.yml @@ -313,34 +313,6 @@ stages: In this stage, we'll add support for `{n,m}`, the [between n and m times](https://docs.microsoft.com/en-us/dotnet/standard/base-types/quantifiers-in-regular-expressions#match-between-n-and-m-times-nm) quantifier. # Multiple matches - - slug: "ge4" - primary_extension_slug: "multiple-matches" - name: "Count matching lines" - difficulty: easy - marketing_md: |- - In this stage, you'll add support for printing the count of matching lines. - - - slug: "ru8" - primary_extension_slug: "multiple-matches" - name: "Print matching lines" - difficulty: easy - marketing_md: |- - In this stage, you'll add support for printing the matching lines. - - - slug: "cy4" - primary_extension_slug: "multiple-matches" - name: "Print line numbers" - difficulty: easy - marketing_md: |- - In this stage, you'll add support for displaying the line numbers of the matching lines. - - - slug: "vq9" - primary_extension_slug: "multiple-matches" - name: "Limit matching lines" - difficulty: medium - marketing_md: |- - In this stage, you'll add support for stopping the pattern search after a specified number of lines have been matched. - - slug: "ss2" primary_extension_slug: "multiple-matches" name: "Print individual matches" diff --git a/stage_descriptions/multiple-matches-01-ge4.md b/stage_descriptions/multiple-matches-01-ge4.md deleted file mode 100644 index 849eea36..00000000 --- a/stage_descriptions/multiple-matches-01-ge4.md +++ /dev/null @@ -1,36 +0,0 @@ -In this stage, you'll add support for printing the count of matching lines. - -### The `-c` option - -The `-c` option, also known as the count option, is used to count the number of lines which match the specified pattern. - -Example Usage: - -```bash -# Two of the three lines contain a digit -echo -e "line1\nline2\nlinethree" | grep -c -E '\d' -2 - -# Both lines contain a digit -# Even though the first line contains multiple occurences of digit, this line is counted only once -echo -e "line1text1text2\nline2 | grep -c -E '\d' -2 -``` - -### Tests - -The tester will execute your program like this: - -```bash -$ echo -e "line1\nline2\nline3" | ./your_program.sh -c -E "pattern" -``` - -If none of the lines match the specified pattern: - -- The exit code of the program should be `1`. -- The output of the program should be `0` - -If at least one line matches the specified pattern: - -- The exit code of the program should be `0`. -- The output of the program should be the number of lines that match the pattern. diff --git a/stage_descriptions/multiple-matches-02-ru8.md b/stage_descriptions/multiple-matches-02-ru8.md deleted file mode 100644 index 33ef2c58..00000000 --- a/stage_descriptions/multiple-matches-02-ru8.md +++ /dev/null @@ -1,30 +0,0 @@ -In this stage, you'll add support for printing the matching lines. - -### Printing the matching lines - -If a line from the standard input is matched, grep prints all the matching lines to the standard output. - -Example usage: - -```bash -$ echo -ne "caats\ndog\ncaaaats" | grep -E "ca+ts" -caats -caaaats -``` - -### Tests - -The tester will execute your program like this: - -```bash -$ echo -ne "dogs\ndog" | ./your_program.sh -E "dogs?" -dogs -dog -``` - -If none of the lines match the specified pattern, your program must: -- Exit with the code 1 - -If at least one line matches the specified pattern, your program must: -- Exit with the code 0 -- Print all the matching lines to the standard output \ No newline at end of file diff --git a/stage_descriptions/multiple-matches-03-cy4.md b/stage_descriptions/multiple-matches-03-cy4.md deleted file mode 100644 index a64863b9..00000000 --- a/stage_descriptions/multiple-matches-03-cy4.md +++ /dev/null @@ -1,37 +0,0 @@ -In this stage, you'll add support for displaying the line numbers of the matching lines. - -### The `-n` option - -The `-n` option, also known as the `line number` option, is used to display the line number of each matching line. - -Example usage: - -```bash -$ echo -ne "dogs\ncat\ndog" | grep -n -E "dogs?" -1:dogs -3:dog -``` - -When the -n option is used, the output is the line number, followed by a colon, followed by that line's text. - -### Tests - -The tester will execute your program like this: - -```bash -$ echo -e "line1\nline2\nline3" | ./your_program.sh -n -E "pattern" -``` - -If none of the lines match the specified pattern: - -- The exit code of your program should be 1. -- No output should be produced by the program to the standard output. - -If at least one line matches the specified pattern: - -- The exit code of your program should be 0. -- All the matching lines should be printed, each preceded by its number and a colon separator. - -### Notes - -1. The line numbering starts from 1, not 0. \ No newline at end of file diff --git a/stage_descriptions/multiple-matches-04-vq9.md b/stage_descriptions/multiple-matches-04-vq9.md deleted file mode 100644 index 5b91fffd..00000000 --- a/stage_descriptions/multiple-matches-04-vq9.md +++ /dev/null @@ -1,35 +0,0 @@ -In this stage, you'll add support for stopping the pattern search after a specified number of lines have been matched. - -### The `-m` option - -The `-m` option, also known as the `max-count` option, is used to stop the search after the specified number of lines have matched the pattern. - -Example usage: - -```bash -# Stop after 1 matching line has been found -$ echo -ne "line1_text11_text2\nline2\nline3_text33" | grep -m 1 -E '\d' -line1_text11_text2 -``` - -### Tests - -The tester will execute your program like this: - -```bash -$ echo -e "line1\nline2\nline3" | ./your_program.sh -m 1 -E "pattern" -``` - -If none of the lines match the specified pattern - -- The exit code of the program should be 1 -- No output should be printed by the program - -If at least one line matches the specified pattern: - -- The exit code of the program should be 0 -- Print matching lines until reaching the `max-count`. Do not print more than the `max-count` lines - -### Notes - -- The tester will only test with a positive value of `max-count`. You don't need to implement the cases where the max count is zero or negative. \ No newline at end of file From a2104014bfae6fa43179d0a5e39b239013e52e72 Mon Sep 17 00:00:00 2001 From: Udeshya Dhungana <075bct095.udeshya@pcampus.edu.np> Date: Fri, 14 Nov 2025 13:01:07 +0545 Subject: [PATCH 5/9] Redo multiple matches extension --- course-definition.yml | 22 +++++++-- stage_descriptions/multiple-matches-01-cj0.md | 31 ++++++++++++ stage_descriptions/multiple-matches-02-ss2.md | 39 +++++++++++++++ stage_descriptions/multiple-matches-03-bo4.md | 42 ++++++++++++++++ stage_descriptions/multiple-matches-05-ss2.md | 48 ------------------- 5 files changed, 130 insertions(+), 52 deletions(-) create mode 100644 stage_descriptions/multiple-matches-01-cj0.md create mode 100644 stage_descriptions/multiple-matches-02-ss2.md create mode 100644 stage_descriptions/multiple-matches-03-bo4.md delete mode 100644 stage_descriptions/multiple-matches-05-ss2.md diff --git a/course-definition.yml b/course-definition.yml index 2eb0aa5b..b8d41ac7 100644 --- a/course-definition.yml +++ b/course-definition.yml @@ -81,7 +81,7 @@ extensions: description_markdown: | In this challenge extension, you'll add support for printing the multiple matching results to your Grep implementation. - Along the way, you'll learn about how to implement the `-c` flag, `-o` flag, and more. + Along the way, you'll learn about how to implement the `-o` flag. stages: - slug: "cq2" @@ -313,9 +313,23 @@ stages: In this stage, we'll add support for `{n,m}`, the [between n and m times](https://docs.microsoft.com/en-us/dotnet/standard/base-types/quantifiers-in-regular-expressions#match-between-n-and-m-times-nm) quantifier. # Multiple matches + - slug: "cj0" + primary_extension_slug: "multiple-matches" + name: "Print a single matching text" + difficulty: medium + marketing_md: |- + In this stage, you'll add support for printing a single matching text to your grep implementation. + - slug: "ss2" primary_extension_slug: "multiple-matches" - name: "Print individual matches" - difficulty: hard + name: "Print multiple matching texts" + difficulty: medium + marketing_md: |- + In this stage, you'll add support for printing multiple matching texts from a single line to your grep implementation. + + - slug: "bo4" + primary_extension_slug: "multiple-matches" + name: "Process multiple input lines" + difficulty: medium marketing_md: |- - In this stage, you'll add support for printing only the matching texts. \ No newline at end of file + In this stage, you'll add support for processing multiple input lines to print all matching texts. \ No newline at end of file diff --git a/stage_descriptions/multiple-matches-01-cj0.md b/stage_descriptions/multiple-matches-01-cj0.md new file mode 100644 index 00000000..5aea8f43 --- /dev/null +++ b/stage_descriptions/multiple-matches-01-cj0.md @@ -0,0 +1,31 @@ +In this stage, you'll add support for printing a single matching text to your grep implementation. + +### The `-o` flag + +The `-o` flag, also known as the `only-matching` flag, is used to print only the matching texts in a separate line. + +Example usage: + +```bash +$ echo -ne "I have one cow" | grep -o -E 'cow' +cow +``` + +The tester will execute your program like this: + +```bash +$ echo -n "The king had 7 daughters" | ./your_program.sh -E "\d" +7 +``` + +If the input line does not match the specified pattern, your program must: +- Exit with the code 1 +- Exit with no printed output + +If the input line matches the specified pattern, your program must: +- Print the matched text to the standard output +- Exit with the code 0 + +### Notes + +- You only need to handle a single line of input and a single occurence of the pattern. We'll get to printing multiple matches and processing multiple lines in the later stages. \ No newline at end of file diff --git a/stage_descriptions/multiple-matches-02-ss2.md b/stage_descriptions/multiple-matches-02-ss2.md new file mode 100644 index 00000000..341a4c33 --- /dev/null +++ b/stage_descriptions/multiple-matches-02-ss2.md @@ -0,0 +1,39 @@ +In this stage, you'll add support for printing multiple matching texts from a single line to your grep implementation. + + +### Printing multiple matches + +If there are multiple matches present in the same line, each of them are printed on a separate line. + +```bash +# The '\d' pattern matches 1 and 0 separately +$ echo -n "The king had 10 children" | grep -o -P '\d' +1 +0 + +# The `\d\d` matches a pair of digits, so each pair (if found) is printed in its own line +$ echo -n "The king had 10 children" | grep -o -P '\d\d' +10 +``` + +### Tests +The tester will execute your program like this: + +```bash +$ echo -e "jekyll and hyde" | ./your_program.sh -o -E "(jekyll|hyde)" +jekyll +hyde +``` + +If none of the lines match the specified pattern, your program must: +- Exit with the code 1 +- Exit with no printed output + +If at least one line matches the pattern, your program must + +- Exit with the code 0 +- Print all the matching parts to the standard output + +### Notes + +- You only need the handle the case of single input line. We'll get to processing multiple input lines in the next stage. \ No newline at end of file diff --git a/stage_descriptions/multiple-matches-03-bo4.md b/stage_descriptions/multiple-matches-03-bo4.md new file mode 100644 index 00000000..bb21d8ad --- /dev/null +++ b/stage_descriptions/multiple-matches-03-bo4.md @@ -0,0 +1,42 @@ +In this stage, you'll add support for processing multiple input lines to print all matching texts. + +### Printing multiple matches from multiple lines + +If there are multiple lines in the input, matches from all lines are printed, each on their own line. + +```bash +# The '\d' pattern matches 1 and 0 separately in multiple lines +$ echo -ne "Line1: 10\nLine2: 42" | grep -o -P '\d' +1 +1 +0 +2 +4 +2 + +# The `\d\d` matches a pair of digits, so each pair (if found) is printed in its own line +$ echo -ne "Line01: 50\nLine02: 42" | grep -o -P '\d\d' +01 +50 +02 +42 +``` + +### Tests + +The tester will execute your program like this: + +```bash +$ echo -e "jekyll and hyde\nmickey mouse" | ./your_program.sh -o -E "(jekyll|hyde|mouse)" +jekyll +hyde +mouse +``` + +If none of the lines match the specified pattern, +- Your program should exit with the code 1 +- No output should be printed + +If at least one line matches the pattern, +- Your program should exit with the code 0 +- All the matching parts from all lines should be printed on their separate lines \ No newline at end of file diff --git a/stage_descriptions/multiple-matches-05-ss2.md b/stage_descriptions/multiple-matches-05-ss2.md deleted file mode 100644 index f2e72e02..00000000 --- a/stage_descriptions/multiple-matches-05-ss2.md +++ /dev/null @@ -1,48 +0,0 @@ -In this stage, you'll add support for printing only the matching texts. - -### The `-o` flag - -The `-o` flag, also known as the `only-matching` flag, is used to print only the matching texts in a separate line. - -Example usage: - -```bash -# The `\d` matches each digit separately, so each digit (if found) is printed in its own line -$ echo -ne "line1_text11_text2\nline2\nline3_text33" | grep -o -E '\d' -1 -1 -1 -2 -2 -3 -3 -3 - -# The `\d\d` matches a pair of digits, so each pair (if found) is printed in its own line -$ echo -ne "line1_text11_text2\nline2\nline3_text33" | grep -o -E '\d\d' -11 -33 - -# Each match is printed in its own line -$ echo -ne "I have 4 cows and 9 cats\nHe has 3 cats" | grep -o -E '\d (cows|cats)' -4 cows -9 cats -3 cats -``` - -### Tests -The tester will execute your program like this: - -```bash -$ echo -e "line1\nline2\nline3" | ./your_program.sh -o -E "pattern" -``` - -If none of the lines match the specified pattern, - -- Your program should exit with the code 1 -- No output should be printed - -If at least one line matches the pattern, - -- Your program should exit with the code 0 -- All the matching parts should be printed in their separate line \ No newline at end of file From 6045ea28917cd796b94bc2dbca5009dc5e75a759 Mon Sep 17 00:00:00 2001 From: Udeshya Dhungana <075bct095.udeshya@pcampus.edu.np> Date: Fri, 14 Nov 2025 13:06:05 +0545 Subject: [PATCH 6/9] Add LLM suggestions --- stage_descriptions/multiple-matches-01-cj0.md | 4 +++- stage_descriptions/multiple-matches-02-ss2.md | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/stage_descriptions/multiple-matches-01-cj0.md b/stage_descriptions/multiple-matches-01-cj0.md index 5aea8f43..35547e23 100644 --- a/stage_descriptions/multiple-matches-01-cj0.md +++ b/stage_descriptions/multiple-matches-01-cj0.md @@ -11,10 +11,12 @@ $ echo -ne "I have one cow" | grep -o -E 'cow' cow ``` +### Tests + The tester will execute your program like this: ```bash -$ echo -n "The king had 7 daughters" | ./your_program.sh -E "\d" +$ echo -n "The king had 7 daughters" | ./your_program.sh -o -E "\d" 7 ``` diff --git a/stage_descriptions/multiple-matches-02-ss2.md b/stage_descriptions/multiple-matches-02-ss2.md index 341a4c33..a931061b 100644 --- a/stage_descriptions/multiple-matches-02-ss2.md +++ b/stage_descriptions/multiple-matches-02-ss2.md @@ -17,6 +17,7 @@ $ echo -n "The king had 10 children" | grep -o -P '\d\d' ``` ### Tests + The tester will execute your program like this: ```bash From 93a58f3d5d829f241d325d0d8af85b2cbf72f231 Mon Sep 17 00:00:00 2001 From: Udeshya Dhungana <075bct095.udeshya@pcampus.edu.np> Date: Fri, 14 Nov 2025 13:13:50 +0545 Subject: [PATCH 7/9] Apply LLM grammar suggestions --- stage_descriptions/multiple-matches-02-ss2.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/stage_descriptions/multiple-matches-02-ss2.md b/stage_descriptions/multiple-matches-02-ss2.md index a931061b..2ed7b90e 100644 --- a/stage_descriptions/multiple-matches-02-ss2.md +++ b/stage_descriptions/multiple-matches-02-ss2.md @@ -3,7 +3,7 @@ In this stage, you'll add support for printing multiple matching texts from a si ### Printing multiple matches -If there are multiple matches present in the same line, each of them are printed on a separate line. +If there are multiple matches present in the same line, each of them is printed on a separate line. ```bash # The '\d' pattern matches 1 and 0 separately @@ -30,11 +30,11 @@ If none of the lines match the specified pattern, your program must: - Exit with the code 1 - Exit with no printed output -If at least one line matches the pattern, your program must +If at least one line matches the pattern, your program must: - Exit with the code 0 - Print all the matching parts to the standard output ### Notes -- You only need the handle the case of single input line. We'll get to processing multiple input lines in the next stage. \ No newline at end of file +- You only need to handle the case of a single input line. We will get to processing multiple input lines in the next stage. \ No newline at end of file From 20021dd5af0cdf57aa0c9ee3fc5de431199ab389 Mon Sep 17 00:00:00 2001 From: Udeshya Dhungana <075bct095.udeshya@pcampus.edu.np> Date: Mon, 17 Nov 2025 09:42:46 +0545 Subject: [PATCH 8/9] Redo suggested stage names ss2, cj0 --- course-definition.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/course-definition.yml b/course-definition.yml index b8d41ac7..277971dd 100644 --- a/course-definition.yml +++ b/course-definition.yml @@ -315,14 +315,14 @@ stages: # Multiple matches - slug: "cj0" primary_extension_slug: "multiple-matches" - name: "Print a single matching text" + name: "Print single match" difficulty: medium marketing_md: |- In this stage, you'll add support for printing a single matching text to your grep implementation. - slug: "ss2" primary_extension_slug: "multiple-matches" - name: "Print multiple matching texts" + name: "Print multiple matches" difficulty: medium marketing_md: |- In this stage, you'll add support for printing multiple matching texts from a single line to your grep implementation. From 7e146bc6abf068fa031c25f1e3cdf091a16a7134 Mon Sep 17 00:00:00 2001 From: Udeshya Dhungana <075bct095.udeshya@pcampus.edu.np> Date: Mon, 24 Nov 2025 11:14:44 +0545 Subject: [PATCH 9/9] Apply LLM suggested fix --- stage_descriptions/multiple-matches-02-ss2.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stage_descriptions/multiple-matches-02-ss2.md b/stage_descriptions/multiple-matches-02-ss2.md index 2ed7b90e..a7917e69 100644 --- a/stage_descriptions/multiple-matches-02-ss2.md +++ b/stage_descriptions/multiple-matches-02-ss2.md @@ -37,4 +37,4 @@ If at least one line matches the pattern, your program must: ### Notes -- You only need to handle the case of a single input line. We will get to processing multiple input lines in the next stage. \ No newline at end of file +- You only need to handle the case of a single input line. We will get to processing multiple input lines in later stages. \ No newline at end of file