title: Get substring before last occurrence of a word in shell script
body: <p>I have a string <code>/abc/xyz/def/xyz/1234/lmn/xyz/7890/uvw</code> in Linux.</p>
  
  <p>I want to extract the substring before the last occurrence of the string <code>xyz</code> using shell script.</p>
  
  <p>Example:</p>
  
  <p>Input:</p>
  
  <pre><code>/abc/xyz/def/xyz/1234/lmn/xyz/7890/uvw
  </code></pre>
  
  <p>Output:</p>
  
  <pre><code>/abc/xyz/def/xyz/1234/lmn
  </code></pre>
  
  <p>I searched online and there are solutions with single character separator, but I couldn't figure out how to get it working with a string separator like <code>xyz</code>.</p>