Quote:
Originally Posted by
steadyonabix
The \t certainly works on Ubuntu using the bash shell
Whether \t is supported or not by sed depends only on the sed implementation itself. The shell is irrelevant. The operating system is irrelevant (except as an indication of which sed implementation is provided by default).
I believe that the only commonly-used sed that supports \t in either portion (regular expression or replacement text) of a substitution command is GNU sed.
According to the document standardizing sed (and the regular expression standard to which it refers), \t is an undefined sequence. When encountered, an implementation could treat it as a tab (as GNU sed does), it could treat it as a literal backslash followed by the letter tee (as just about every other sed does), it could abort with a syntax error, or it could choose to delete a file (though this is extremely unlikely
). The same is true of any sequence consisting of a backslash followed by an ordinary character, except for ...
Quote:
* The characters ')', '(', '{', and '}'
* The digits 1 to 9 inclusive (see BREs Matching Multiple Characters)
* A character inside a bracket expression
and
Quote:
The escape sequence '\n' shall match a <newline> embedded in the pattern space. A literal <newline> shall not be used in the BRE of a context address or in the substitute function.
Source of the 1st quote, which applies to all basic regular expressions:
Regular Expressions
Source of the 2nd quote, which applies to sed regular expressions :
sed
Long story short, if you use \t in a sed command, it will only work with GNU sed, which practically means Linux-only. Don't expect such scripts to run as intended on non-Linux platforms.
Regards,
Alister