I have a database upload file with a field separated by a <TAB> symbol. I run this file through sed to replace any occurrences of <TAB> <TAB> with <TAB> \ N <TAB>. This is so that when a file is uploaded to MySQL, \ N is interpreted as NULL.
Command sed / \ t \ t / \ t \ N \ t / g; 'almost works, except that it replaces only the first instance, for example. "... <TAB> <TAB> <TAB> ..." becomes "... <TAB> \ N <TAB> <TAB> ...".
If I use 's / \ t \ t / \ t \ N \ t / g; s / \ t \ t / \ t \ N \ t / g; ' it replaces more instances.
I have an opinion that, despite the / g modifier, this is due to the fact that the end of one match is the beginning of another.
Can someone explain what is happening and suggest a sed command that will work, or do I need to execute a loop.
I know that maybe I can switch to awk, perl, python, but I want to know what happens in sed.
source share