title: SED find string using variable, edit, and then substitution
body: <p>I’m having some issues trying to edit a file with SED using a variable that has forward slashes in it.</p>
  
  <p>The file I’m trying to edit “checksum” has the following contents…</p>
  
  <pre><code>758f9775093bf885dbc963cba1aec732,/bin/bash
  1b45027142521f2a1c3d95891770eb47,/etc/grub.conf
  2a34dc288f7994cc7b1b338605ef8775,/etc/hosts
  03f670845fe199955f9a0babecbda9a0,/etc/networks
  </code></pre>
  
  <p>I want to search for  the string “/bin/bash” using a variable (file_path=“/bin/bash”) and when I find that string, remove everything up to the “,” and replace with the work “VALID”.  </p>
  
  <p>Here’s my sed syntax and attempts below, however it fails when I try to use the variable.  Any suggestions?</p>
  
  <p>Success without variable</p>
  
  <pre><code># sed '\/bin\/bash/ s/^.*,/VALID,/g' checksum
  VALID,/bin/bash
  1b45027142521f2a1c3d95891770eb47,/etc/grub.conf
  2a34dc288f7994cc7b1b338605ef8775,/etc/hosts
  03f670845fe199955f9a0babecbda9a0,/etc/networks
  </code></pre>
  
  <p>Failure with variable</p>
  
  <pre><code># file_path="/bin/bash"
  # echo $file_path
  /bin/bash
  
  # sed '/$file_path/ s/^.*,/VALID,/g' checksum
  758f9775093bf885dbc963cba1aec732,/bin/bash
  1b45027142521f2a1c3d95891770eb47,/etc/grub.conf
  2a34dc288f7994cc7b1b338605ef8775,/etc/hosts
  03f670845fe199955f9a0babecbda9a0,/etc/networks
  </code></pre>
  
  <p>I’ve tried wrapping the variable in quotes, {} and still had the same failures:</p>
  
  <pre><code># sed '/"$file_path"/ s/^.*,/VALID,/g' checksum
  758f9775093bf885dbc963cba1aec732,/bin/bash
  1b45027142521f2a1c3d95891770eb47,/etc/grub.conf
  2a34dc288f7994cc7b1b338605ef8775,/etc/hosts
  03f670845fe199955f9a0babecbda9a0,/etc/networks
  
  # sed '/{$file_path}/ s/^.*,/VALID,/g' checksum
  758f9775093bf885dbc963cba1aec732,/bin/bash
  1b45027142521f2a1c3d95891770eb47,/etc/grub.conf
  2a34dc288f7994cc7b1b338605ef8775,/etc/hosts
  03f670845fe199955f9a0babecbda9a0,/etc/networks
  </code></pre>
  
  <p>I’ve also used “|” as the escape character.</p>
  
  <pre><code># sed '|{$file_path}| s|^.*,|VALID,|g' checksum
  sed: -e expression #1, char 1: unknown command: `|'
  </code></pre>
  
  <p>Any suggestions on how to accomplish this?</p>
  
  <pre><code># sed --version
  GNU sed version 4.2.1
  </code></pre>