title: Sed/Awk to delete second occurence of string - platform independent
body: <p>I'm looking for a line in bash that would work on both linux as well as OS X to remove the second line containing the desired string:</p>
  
  <pre><code>Header
  1
  2
  ...
  Header
  10
  11
  ...
  </code></pre>
  
  <p>Should become</p>
  
  <pre><code>Header
  1
  2
  ...
  10
  11
  ...
  </code></pre>
  
  <p>My first attempt was using the deletion option of sed:</p>
  
  <pre><code>sed -i '/^Header.*/d' file.txt
  </code></pre>
  
  <p>But well, that removes the first occurence as well. </p>
  
  <p><a href="https://stackoverflow.com/questions/17910718/how-to-delete-the-matching-pattern-from-given-occurrence">How to delete the matching pattern from given occurrence</a> suggests to use something like this:</p>
  
  <pre><code>sed -i '/^Header.*/{2,$d} file.txt
  </code></pre>
  
  <p>But on OS X that gives the error</p>
  
  <pre><code>sed: 1: "/^Header.*/{2,$d}": extra characters at the end of d command
  </code></pre>
  
  <p>Next, i tried substitution, where I know how to use <code>2,$</code>, and subsequent empty line deletion:</p>
  
  <pre><code>sed -i '2,$s/^Header.*//' file.txt
  sed -i '/^\s*$/d' file.txt
  </code></pre>
  
  <p>This works on Linux, but on OS X, as mentioned here <a href="https://stackoverflow.com/questions/4247068/sed-command-failing-on-mac-but-works-on-linux">sed command with -i option failing on Mac, but works on Linux</a> , you'd have to use</p>
  
  <pre><code>sed -i '' '2,$s/^Header.*//' file.txt
  sed -i '' '/^\s*$/d' file.txt
  </code></pre>
  
  <p>And this one in return doesn't work on Linux.</p>
  
  <p>My question then, isn't there a simple way to make this work in any Bash? Doesn't have to be sed, but should be as shell independent as possible and i need to modify the file itself.</p>