From owner-freebsd-stable@FreeBSD.ORG Tue Sep 19 22:53:58 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 733FD16A407 for ; Tue, 19 Sep 2006 22:53:58 +0000 (UTC) (envelope-from fcash@ocis.net) Received: from smtp.sd73.bc.ca (mailtest.sd73.bc.ca [142.24.13.140]) by mx1.FreeBSD.org (Postfix) with ESMTP id 1F77B43D46 for ; Tue, 19 Sep 2006 22:53:58 +0000 (GMT) (envelope-from fcash@ocis.net) Received: from localhost (localhost [127.0.0.1]) by localhost.sd73.bc.ca (Postfix) with ESMTP id 3FB9C18CE80; Tue, 19 Sep 2006 16:03:35 -0700 (PDT) X-Virus-Scanned: by amavisd-new using ClamAV at sd73.bc.ca Received: from smtp.sd73.bc.ca ([127.0.0.1]) by localhost (smtp.sd73.bc.ca [127.0.0.1]) (amavisd-new, port 10024) with LMTP id cpmDLsguaKEo; Tue, 19 Sep 2006 16:03:34 -0700 (PDT) Received: from webmail.sd73.bc.ca (unknown [10.10.10.17]) by smtp.sd73.bc.ca (Postfix) with ESMTP id D81BA18CD4D; Tue, 19 Sep 2006 16:03:33 -0700 (PDT) Received: from 192.168.0.10 (SquirrelMail authenticated user fcash) by webmail.sd73.bc.ca with HTTP; Tue, 19 Sep 2006 15:53:56 -0700 (PDT) Message-ID: <54894.192.168.0.10.1158706436.squirrel@webmail.sd73.bc.ca> In-Reply-To: References: Date: Tue, 19 Sep 2006 15:53:56 -0700 (PDT) From: "Freddie Cash" To: "SigmaX asdf" User-Agent: SquirrelMail/1.5.1 MIME-Version: 1.0 Content-Type: text/plain;charset=iso-8859-1 Content-Transfer-Encoding: 8bit Cc: stable@freebsd.org Subject: Re: sed and comma-delimited file X-BeenThere: freebsd-stable@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Production branch of FreeBSD source code List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 19 Sep 2006 22:53:58 -0000 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 You can probably even remove the cat and just use awk on the file directly. ---- Freddie Cash fcash@ocis.net