title: Extracting string between two slashes using sed
body: <p>I am trying to use sed to extract a specific string from a line within a file. Currently I am reading in a file with a while loop and searching for a specific string. When that string is found I am extracting it, but I then need to use sed to parse the output so that I only get the string between two slashes (Its a directory name, so I need to keep both the starting and trailing slashes if possible). Here is the loop I am running to search for a file:</p>
  
  <pre><code>#!/bin/sh
  file=configFile.conf
  while read line 
  do
      if  echo "$line" | grep -q "directory_root" 
      then DIR_ROOT="$line"
  fi
  done &lt; "$file"
  echo $DIR_ROOT
  exit 0
  </code></pre>
  
  <p>The while loop works and echoes the following string:</p>
  
  <pre><code>directory_root /root/config/data/
  </code></pre>
  
  <p>I then need to use sed in order to get the following output in order to pass the correct directory name in to another script:</p>
  
  <pre><code>/root/
  </code></pre>
  
  <p>Is it possible to use sed and regular expressions to extract only the above from the echoed output?</p>
  
  <p>Thanks</p>