From owner-freebsd-stable@FreeBSD.ORG Fri Sep 22 06:47:53 2006 Return-Path: X-Original-To: stable@freebsd.org Delivered-To: freebsd-stable@FreeBSD.ORG Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 606BB16A494 for ; Fri, 22 Sep 2006 06:47:53 +0000 (UTC) (envelope-from bill@celestial.com) Received: from mail.mi.celestial.com (hayek.celestial.com [192.136.111.12]) by mx1.FreeBSD.org (Postfix) with ESMTP id C54B043D6A for ; Fri, 22 Sep 2006 06:47:52 +0000 (GMT) (envelope-from bill@celestial.com) Received: from localhost (localhost [127.0.0.1]) by mail.mi.celestial.com (Postfix) with ESMTP id 4C6CB137C28; Thu, 21 Sep 2006 23:47:51 -0700 (PDT) Received: from mail.mi.celestial.com ([127.0.0.1]) by localhost (alexis.mi.celestial.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id 10656-05-2; Thu, 21 Sep 2006 23:47:18 -0700 (PDT) Received: by mail.mi.celestial.com (Postfix, from userid 203) id B85A5137C79; Thu, 21 Sep 2006 23:47:17 -0700 (PDT) Date: Thu, 21 Sep 2006 23:47:16 -0700 From: Bill Campbell To: stable@freebsd.org Message-ID: <20060922064716.GA10602@alexis.mi.celestial.com> Mail-Followup-To: stable@freebsd.org References: <54894.192.168.0.10.1158706436.squirrel@webmail.sd73.bc.ca> <002101c6dc46$470b1d50$0000fea9@gsicomp.on.ca> <60472.24.70.153.246.1158901743.squirrel@webmail.sd73.bc.ca> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <60472.24.70.153.246.1158901743.squirrel@webmail.sd73.bc.ca> User-Agent: Mutt/1.4.2.1i X-Virus-Scanned: amavisd-new at mi.celestial.com Cc: Subject: Re: sed and comma-delimited file X-BeenThere: freebsd-stable@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: freebsd@celestial.com List-Id: Production branch of FreeBSD source code List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 22 Sep 2006 06:47:53 -0000 On Thu, Sep 21, 2006, Freddie Cash wrote: >On Tue, September 19, 2006 4:49 pm, Matt Emmerton wrote: >>> On Tue, September 19, 2006 9:26 am, SigmaX asdf wrote: >>>> I have a series of comma-delimited text files with fourteen >>>> columns of data and several hundred rows. I want to use a short >>>> shell script to strip them of the last 9 columns, leaving the same >>>> file but with just five of its columns. I can do it in C++, but >>>> that seems like overkill. How would I go about doing it with sed >>>> or a similar utility? > >>> cat file | awk -F"," '{ printf "%s,%s,%s,%s,%s\n",$1,$2,$3,$4,$5 >>> }' > newfile > >> What's wrong with this? >> cat file | cut -f-5 -c';' > newfile > >[shrug] It uses cut, which I've never used or even heard of??? :) I strongly recommend getting a copy of the book ``Unix Text Processing'' by Dougherty and O'Reilly which is far and away the best I've seen for using UNIX tools. I think it's out of print, and hard copies are probably found at http://www.bookfinder.com/ There's also a free PDF version available from O'Reilly. Bill -- INTERNET: bill@Celestial.COM Bill Campbell; Celestial Systems, Inc. UUCP: camco!bill PO Box 820; 6641 E. Mercer Way FAX: (206) 232-9186 Mercer Island, WA 98040-0820; (206) 236-1676 URL: http://www.celestial.com/ When I hear a man applauded by the mob I always feel a pang of pity for him. All he has to do to be hissed is to live long enough. -- H.L. Mencken, ``Minority Report''