From owner-freebsd-questions@FreeBSD.ORG Thu Jan 29 08:40:56 2004 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id C35DD16A4CF for ; Thu, 29 Jan 2004 08:40:56 -0800 (PST) Received: from dan.emsphone.com (dan.emsphone.com [199.67.51.101]) by mx1.FreeBSD.org (Postfix) with ESMTP id 6BC1843D4C for ; Thu, 29 Jan 2004 08:40:55 -0800 (PST) (envelope-from dan@dan.emsphone.com) Received: (from dan@localhost) by dan.emsphone.com (8.12.10/8.12.10) id i0TGetJK022528; Thu, 29 Jan 2004 10:40:55 -0600 (CST) (envelope-from dan) Date: Thu, 29 Jan 2004 10:40:54 -0600 From: Dan Nelson To: zhangweiwu@realss.com Message-ID: <20040129164054.GC31560@dan.emsphone.com> References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-OS: FreeBSD 5.2-CURRENT X-message-flag: Outlook Error User-Agent: Mutt/1.5.5.1i cc: questions@freebsd.org Subject: Re: use \000 in sed X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 29 Jan 2004 16:40:56 -0000 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