sed and comma-delimited file

Freddie Cash fcash at ocis.net
Thu Sep 21 22:09:26 PDT 2006


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???  :)

----
Freddie Cash
fcash at ocis.net



More information about the freebsd-stable mailing list