title: bash display parts of a variable that contains a path
body: <p>I am trying to output parts of a file path but remove the file name and some levels of the path.</p>
  
  <p>Currently I have a for loop doing a lot of things, but I am creating a variable from the full file path and would like to strip some bits out.</p>
  
  <p>For example</p>
  
  <pre><code>for f in (find /path/to/my/file - name *.ext)
  </code></pre>
  
  <p>will give me </p>
  
  <pre><code>$f = /path/to/my/file/filename.ext
  </code></pre>
  
  <p>What I want to do is printf/echo some of that variable. I know I can do:</p>
  
  <pre><code>printf ${f#/path/to/}
  my/file/filename.ext
  </code></pre>
  
  <p>But I would like to remove the filename and end up with:</p>
  
  <pre><code>my/file
  </code></pre>
  
  <p>Is there any easy way to do this without having to use sed/awk etc?</p>