# Read Text File up to specific word and stop

**URL:** <https://forum.knime.com/t/read-text-file-up-to-specific-word-and-stop/79570>\
**Category:** KNIME Analytics Platform\
**Tags:** text-mining\
**Created:** [May 20, 2024, 4:31pm UTC](https://forum.knime.com/t/read-text-file-up-to-specific-word-and-stop/79570 "2024-05-20T16:31:11Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![love\_hate\_knime](https://forum-cdn.knime.com/user_avatar/forum.knime.com/love_hate_knime/32/67882_2.png) [@love\_hate\_knime](https://forum.knime.com/u/love_hate_knime)\
**Post date:** [May 20, 2024, 4:31pm UTC](https://forum.knime.com/t/read-text-file-up-to-specific-word-and-stop/79570/1 "2024-05-20T16:31:12Z")

</div>

Hello-  
I have a txt file with 5000 lines in it - I want knime to read the document, and return everything its read, up to a specific word. I am unsure how to do this in KNIME - any help would be greatly appreciated!

---

<div class="post-metadata">

**Author:** ![rfeigel](https://forum-cdn.knime.com/letter_avatar_proxy/v4/letter/r/7ea924/32.png) [@rfeigel](https://forum.knime.com/u/rfeigel)\
**Post date:** [May 20, 2024, 5:05pm UTC](https://forum.knime.com/t/read-text-file-up-to-specific-word-and-stop/79570/2 "2024-05-20T17:05:03Z")

</div>

Are you reading the entire file and searching for the word or reading each row separately and searching for the same word in each row?

---

<div class="post-metadata">

**Author:** ![love\_hate\_knime](https://forum-cdn.knime.com/user_avatar/forum.knime.com/love_hate_knime/32/67882_2.png) [@love\_hate\_knime](https://forum.knime.com/u/love_hate_knime)\
**Post date:** [May 20, 2024, 5:17pm UTC](https://forum.knime.com/t/read-text-file-up-to-specific-word-and-stop/79570/3 "2024-05-20T17:17:21Z")

</div>

I am reading each row - looking for a given word. Once found, I want all rows before that, returned in my output.

---

<div class="post-metadata">

**Author:** ![takbb](https://forum-cdn.knime.com/user_avatar/forum.knime.com/takbb/32/57077_2.png) [@takbb](https://forum.knime.com/u/takbb)\
**Post date:** [May 20, 2024, 6:19pm UTC](https://forum.knime.com/t/read-text-file-up-to-specific-word-and-stop/79570/4 "2024-05-20T18:19:25Z")

</div>

Hi @love_hate_knime , if it’s only 5000 lines, I’d think that reading the whole file in and then using something like Rule Engine to write a marker on any row that contains the word, followed by a Table Splitter to return all rows up to that marker would do the job:

e.g.

![image](https://forum-cdn.knime.com/uploads/default/original/3X/6/f/6f66af3ac896c47f2c329e0dac59c1d7d3dd18e6.png)

 ![image](https://forum-cdn.knime.com/uploads/default/original/3X/1/d/1d266abe1652d4b01173bb72673fb79afe376758.png)

`$MemoText$ MATCHES ".*\bMyWordHere\b.*" => "X"`

The `\b` in regex signifies a “Word Boundary”

 ![image](https://forum-cdn.knime.com/uploads/default/original/3X/f/3/f3c4a0132406729c6f7e35774ae9549f2286f661.png)

Then the top port of the Table Splitter will have your required rows.

---

<div class="post-metadata">

**Author:** ![love\_hate\_knime](https://forum-cdn.knime.com/user_avatar/forum.knime.com/love_hate_knime/32/67882_2.png) [@love\_hate\_knime](https://forum.knime.com/u/love_hate_knime)\
**Post date:** [May 20, 2024, 8:41pm UTC](https://forum.knime.com/t/read-text-file-up-to-specific-word-and-stop/79570/5 "2024-05-20T20:41:10Z")

</div>

AWESOME! Thank you so MUCH! This worked wonderfully!

---

<div class="post-metadata">

**Author:** ![takbb](https://forum-cdn.knime.com/user_avatar/forum.knime.com/takbb/32/57077_2.png) [@takbb](https://forum.knime.com/u/takbb)\
**Post date:** [May 20, 2024, 11:17pm UTC](https://forum.knime.com/t/read-text-file-up-to-specific-word-and-stop/79570/6 "2024-05-20T23:17:16Z")

</div>

Hi @love_hate_knime , you’re welcome. Glad it worked for you.

 ![image](https://forum-cdn.knime.com/uploads/default/original/3X/c/a/ca4acabdb49fda61a0c1dde36b3fc4ca674db1a5.png)

---

<div class="post-metadata">

**Author:** ![system](https://forum-cdn.knime.com/uploads/default/original/1X/ab3ccf34482a0329361734a18199390177204f15.png) [@system](https://forum.knime.com/u/system)\
**Post date:** [May 27, 2024, 11:17pm UTC](https://forum.knime.com/t/read-text-file-up-to-specific-word-and-stop/79570/7 "2024-05-27T23:17:47Z")

</div>

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