# \#OL9 Multi Line file search, line not found

**URL:** <https://forum.codecrafters.io/t/ol9-multi-line-file-search-line-not-found/15466>\
**Category:** Challenges\
**Tags:** challenge:grep\
**Created:** [October 29, 2025, 7:20pm UTC](https://forum.codecrafters.io/t/ol9-multi-line-file-search-line-not-found/15466 "2025-10-29T19:20:24Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Suchydudul](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/suchydudul/32/18629_2.png) [@Suchydudul](https://forum.codecrafters.io/u/Suchydudul)\
**Post date:** [October 29, 2025, 7:20pm UTC](https://forum.codecrafters.io/t/ol9-multi-line-file-search-line-not-found/15466/1 "2025-10-29T19:20:25Z")

</div>

I’m stuck on Stage #OL9

I presume the tester cant read my output correctly, in the previous test where there was only one line everything worked

I’ve tried changing the print statement i many ways (removing newline, using just one print outside the loop etc.)

Here are my logs:

#OL9 where it fails

```auto
[tester::#OL9] Running tests for Stage #OL9 (File Search - Search a multi-line file)
[tester::#OL9] [setup] echo "watermelon" > "fruits-5243.txt"
[tester::#OL9] [setup] echo "plum" >> "fruits-5243.txt"
[tester::#OL9] [setup] echo "blueberry" >> "fruits-5243.txt"
[tester::#OL9] [setup] echo "strawberry" >> "fruits-5243.txt"
[tester::#OL9] $ ./your_program.sh -E .+berry fruits-5243.txt
[your_program] fruits-5243.txt:blueberry
[your_program] fruits-5243.txt:strawberry
[tester::#OL9] ✓ Received exit code 0.
[tester::#OL9] Expected 2 line(s) in output, only found 0 matching line(s). Missing match(es):
[tester::#OL9] ⨯ Line not found: "blueberry"
[tester::#OL9] ⨯ Line not found: "strawberry"
[tester::#OL9] Test failed (try setting 'debug: true' in your codecrafters.yml to see more details)

```

#IS6, the previous test case that worked

```auto
[tester::#IS6] Running tests for Stage #IS6 (File Search - Search multiple files)
[tester::#IS6] [setup] echo "lemon" > "fruits-4555.txt"
[tester::#IS6] [setup] echo "blueberry" >> "fruits-4555.txt"
[tester::#IS6] [setup] echo "carrot" > "vegetables-2011.txt"
[tester::#IS6] [setup] echo "broccoli" >> "vegetables-2011.txt"
[tester::#IS6] $ ./your_program.sh -E le.+$ fruits-4555.txt vegetables-2011.txt
[your_program] fruits-4555.txt:lemon
[tester::#IS6] ✓ Received exit code 0.
[tester::#IS6] ✓ Stdout contains 1 expected line(s)
[tester::#IS6] $ ./your_program.sh -E missing_fruit fruits-4555.txt vegetables-2011.txt
[tester::#IS6] ✓ Received exit code 1.
[tester::#IS6] ✓ Stdout contains 1 expected line(s)
[tester::#IS6] $ ./your_program.sh -E carrot fruits-4555.txt vegetables-2011.txt
[your_program] vegetables-2011.txt:carrot
[tester::#IS6] ✓ Received exit code 0.
[tester::#IS6] ✓ Stdout contains 1 expected line(s)
[tester::#IS6] Test passed.

```

And here’s a snippet of my code, I’ve included the whole main but the part that matters is commented :

```python
def main():

    pattern = sys.argv[2]
    if sys.argv[1] != "-E":
        print("Expected first argument to be '-E'")
        exit(1)
    
    arguments = len(sys.argv)

    if arguments == 3:
        input_line = sys.stdin.read()

        if checks (input_line, pattern) == True:
            print(input_line)
            exit(0)
        else:
            exit(1)
##The part which is relevant to the challenge
    found = False
    for file_name in sys.argv[3:]:
        with open(file_name) as file:

            for input_line in file:
                input_line = input_line.rstrip("\n")
                if checks(input_line, pattern): #Pattern matching
                    print(f"{file_name}:{input_line}")
                    found = True          
    if found:
        exit(0)
    else:
        exit(1)

```

---

<div class="post-metadata">

**Author:** ![andy1li](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/andy1li/32/10_2.png) [@andy1li](https://forum.codecrafters.io/u/andy1li)\
**Post date:** [October 29, 2025, 7:32pm UTC](https://forum.codecrafters.io/t/ol9-multi-line-file-search-line-not-found/15466/4 "2025-10-29T19:32:34Z")

</div>

Hey @Suchydudul, the file name prefixes are only necessary when you’re searching across multiple files. For a single file, you should omit them.

 ![image](https://canada1.discourse-cdn.com/flex003/uploads/codecrafters/original/3X/1/4/14e0302db3e55ae035b111abf313c5c683bac1e6.png)

Let me know if anything’s unclear!

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex003/uploads/codecrafters/original/3X/7/0/700657133935c15703e22c7c8870394f6e6dc27d.svg) [@system](https://forum.codecrafters.io/u/system)\
**Post date:** [November 3, 2025, 7:33pm UTC](https://forum.codecrafters.io/t/ol9-multi-line-file-search-line-not-found/15466/6 "2025-11-03T19:33:22Z")

</div>

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.
