1753935 Members
9612 Online
108811 Solutions
New Discussion юеВ

weird sed

 
SOLVED
Go to solution
Qing Zhu
Advisor

weird sed

OS: tru64unix V4.0G, Shell: csh
# which sed
/usr/bin/sed
# echo "a b" | sed 's/ /\t/'
atb

???
I am expecting a TAB between "a" and "b", not "atb", what am I doing wrong?
Seems sed won't recognize all escape sequences such as \n,\t,\r,\b ...
Anyone have comment on this? much appreciated.
3 REPLIES 3
Qing Zhu
Advisor

Re: weird sed


# echo "a b" | sed 's/ /\\\t/'
a\tb

Also not what I wanted :-(
Hein van den Heuvel
Honored Contributor
Solution

Re: weird sed

I think that the \t convention is unfortunately for output only.

For input, just type in a tab!


a reference in this area:

http://www.unixguide.net/unix/sedoneliner.shtml
:
"USE OF '\t' IN SED SCRIPTS: For clarity in documentation, we have used
the expression '\t' to indicate a tab character (0x09) in the scripts.
However, most versions of sed do not recognize the '\t' abbreviation,
so when typing these scripts from the command line, you should press
the TAB key instead. '\t' is supported as a regular expression
metacharacter in awk, perl, and in a few implementations of sed. "

Hein.
Qing Zhu
Advisor

Re: weird sed

Thanks Hein.