I have a file with multiple lines of text similar to:

```
foo
1
2
3
bar
fool
1
2
3
bar
food
1
2
3
bar

```

So far the following gives me a closer answer:

```
sed -n '/foo/,/bar/ p' file.txt | sed -e '$d'

```

...but it fails by introducing duplicates if it encounters words like "food" or "fool". I want to make the code above do a whole word match only (i.e. grep -w), but inserting the \b switch doesn't seem to work:

```
sed -n '/foo/\b,/bar/ p' file.txt | sed -e '$d'

```

I would like to print anything after "foo" (including the first foo) up until "bar", but matching only "foo", and not "foo1".