NOT a solution to the original question but for posterity: this question is about second occurrence in a line and provided solutions works absolutely fine. If you are new to sed (like me) and wants to replace the second occurrence in the entire file, have a look at: sed / awk match second occurrence of regex in a file, and replace whole line