Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 29 Jan 2004 10:40:54 -0600
From:      Dan Nelson <dnelson@allantgroup.com>
To:        zhangweiwu@realss.com
Cc:        questions@freebsd.org
Subject:   Re: use \000 in sed
Message-ID:  <20040129164054.GC31560@dan.emsphone.com>
In-Reply-To: <Law11-F24kd4grUYzTB00027121@hotmail.com>
References:  <Law11-F24kd4grUYzTB00027121@hotmail.com>

next in thread | previous in thread | raw e-mail | index | archive | help
In the last episode (Jan 30), Zhang Weiwu said:
> Dan Nelson wrote:
> >I'm not sure that sed can process \123-style octal characters, since
> >it already uses the \ character for backreferences.  Since you're
> >only replacing one letter, you can use tr:
> >
> >manpath | tr ':' '\000' | xargs -0 ls 
> >
> oh Brilliant, i almost forgot this command!
> 
> But once I need to work with complex replacement, do I have to use
> the two commands together?
> 
> #cmd... | tr .... | sed ...

Maybe.  After reading a bit about xargs, here's an alternate way using
only sed:

manpath | sed -e 's/ /\\ /g' -e 's/:/ /g' | xargs -0 ls

First you escape any spaces in the input, then you replace : with
space.  If you have even weirder pathnames, like ones with quotes or
backslashes in them, you can use this:

sed -e 's/\([^:]\)/\\\1/g' -e 's/:/ /g'

which will backslash-escape everything except colons.

-- 
	Dan Nelson
	dnelson@allantgroup.com



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20040129164054.GC31560>