Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 19 Sep 2006 14:35:31 -0400 (EDT)
From:      Thomas David Rivers <rivers@dignus.com>
To:        fydernix@gmail.com, jhs@berklix.org
Cc:        freebsd-stable@freebsd.org
Subject:   Re: sed and comma-delimited file
Message-ID:  <200609191835.k8JIZV167961@lakes.dignus.com>
In-Reply-To: <200609191809.k8JI9Pva086909@fire.jhs.private>

next in thread | previous in thread | raw e-mail | index | archive | help
"SigmaX asdf" <fydernix@gmail.com> 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



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200609191835.k8JIZV167961>