 <p>Here is a <code>gnu awk</code> solution (due to multiple characters in <code>RS</code>):</p> <pre><code>awk -v RS=" |\n" '/([yeo])$/' file apple tomato empty </code></pre> <p>Here <code>RS</code> is set to space or newline, so it will run one and one word on each line.</p>