From owner-freebsd-questions@FreeBSD.ORG Mon Jan 5 18:22:27 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 CCC2816A4CE for ; Mon, 5 Jan 2004 18:22:27 -0800 (PST) Received: from madras.dyndns.org (dsl-137.241.240.220.dsl.comindico.com.au [220.240.241.137]) by mx1.FreeBSD.org (Postfix) with ESMTP id E78B543D49 for ; Mon, 5 Jan 2004 18:22:22 -0800 (PST) (envelope-from ggop@madras.dyndns.org) Received: from madras.dyndns.org (localhost [127.0.0.1]) by madras.dyndns.org (8.12.9p1/8.12.9) with ESMTP id i062Kw7v008193; Tue, 6 Jan 2004 13:20:58 +1100 (EST) (envelope-from ggop@madras.dyndns.org) Received: (from ggop@localhost) by madras.dyndns.org (8.12.9p1/8.12.9/Submit) id i062Ksjd008188; Tue, 6 Jan 2004 13:20:54 +1100 (EST) Date: Tue, 6 Jan 2004 13:20:52 +1100 From: Gautam Gopalakrishnan To: Malcolm Kay Message-ID: <20040106022052.GA8122@madras.dyndns.org> References: <200401061230.42038.malcolm.kay@internode.on.net> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <200401061230.42038.malcolm.kay@internode.on.net> User-Agent: Mutt/1.4.1i cc: Zhang Weiwu cc: questions@freebsd.org cc: zhangweiwu@realss.com Subject: Re: help me with this sed expression 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: Tue, 06 Jan 2004 02:22:27 -0000 On Tue, Jan 06, 2004 at 12:30:42PM +1030, Malcolm Kay wrote: > On Mon, 5 Jan 2004 22:19, Zhang Weiwu wrote: > > Hello. I've worked an hour to figure out a serial of sed command to process > > some text (without any luck, you kown I'm kinda newbie). I really > > appreciate your help. > > > > The original text file is in this form -- for each line: > > one Chinese word then one or two English word seperated by space. > > > > I tried to do things like s/\(.*\)\([a-z]*\)/\2 \1/ but the first \(.*\) is > > too greedy and included the rest [a-z]. > > Well the greedy part is easily fixed with: > s/\([^a-z]*\)\([a-z]*\)/\2 \1/ > > But this will not work for those lines with 2 english words. The following should: > % sed -n -e 's/\([^a-z]*\)\([a-z]*\) .*/\2 \1/p' -e 's/\([^a-z]*\)[a-z]* \([a-z]*\)/\2 \1/p' original > target I think awk is easier: awk '{print $2 " " $3 " " $1}' original | tr -s > target Gautam