use \000 in sed
    Dan Nelson 
    dnelson at allantgroup.com
       
    Thu Jan 29 08:40:56 PST 2004
    
    
  
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 at allantgroup.com
    
    
More information about the freebsd-questions
mailing list