From owner-freebsd-stable@FreeBSD.ORG Tue Sep 19 18:32:25 2006 Return-Path: X-Original-To: freebsd-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 C64B416A47B for ; Tue, 19 Sep 2006 18:32:25 +0000 (UTC) (envelope-from rivers@dignus.com) Received: from dignus.com (mail.dignus.com [209.42.196.2]) by mx1.FreeBSD.org (Postfix) with ESMTP id 1433C43D73 for ; Tue, 19 Sep 2006 18:32:24 +0000 (GMT) (envelope-from rivers@dignus.com) Received: from lakes.dignus.com (lakes.dignus.com [10.1.0.3]) by dignus.com (8.13.1/8.13.1) with ESMTP id k8JIQ2Te083217; Tue, 19 Sep 2006 14:26:02 -0400 (EDT) (envelope-from rivers@dignus.com) Received: (from rivers@localhost) by lakes.dignus.com (8.11.6/8.11.3) id k8JIZV167961; Tue, 19 Sep 2006 14:35:31 -0400 (EDT) (envelope-from rivers) Date: Tue, 19 Sep 2006 14:35:31 -0400 (EDT) From: Thomas David Rivers Message-Id: <200609191835.k8JIZV167961@lakes.dignus.com> To: fydernix@gmail.com, jhs@berklix.org In-Reply-To: <200609191809.k8JI9Pva086909@fire.jhs.private> X-Spam-Status: No, score=-2.8 required=5.0 tests=ALL_TRUSTED autolearn=failed version=3.0.1 X-Spam-Checker-Version: SpamAssassin 3.0.1 (2004-10-22) on office.dignus.com Cc: freebsd-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 18:32:25 -0000 "SigmaX asdf" wrote: > Yo; > > 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? Uh.. is there no reason the cut(1) program doesn't do this? #!/bin/sh cat file | cut -d',' -f1-5 > /tmp/t.$$ rm -f file mv /tmp/t.$$ file This doesn't preserve permissions, etc... but - it's pretty straight-forward. - Dave Rivers - -- rivers@dignus.com Work: (919) 676-0847 Get your mainframe programming tools at http://www.dignus.com