sed and comma-delimited file
Bill Campbell
freebsd at celestial.com
Thu Sep 21 23:47:53 PDT 2006
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 at 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''
More information about the freebsd-stable
mailing list