Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > basic question...

Reply
Thread Tools

basic question...

 
 
mopthisandthat@hotmail.com
Guest
Posts: n/a
 
      03-22-2006
Hello,

Suppose "OOO.csv" is a data file with 9 columns, and I want to create a
new file that is consisted of 2nd, 5th, and 7th columns of the OOO.csv
(i.e., subset of the original), how do I do this?

Thanks.

 
Reply With Quote
 
 
 
 
Robert Klemme
Guest
Posts: n/a
 
      03-22-2006

<kidding>This is a Ruby and not a Basic group.</kidding>

http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
> Suppose "OOO.csv" is a data file with 9 columns, and I want to create a
> new file that is consisted of 2nd, 5th, and 7th columns of the OOO.csv
> (i.e., subset of the original), how do I do this?


Use CSV for parsing and writing:

http://www.ruby-doc.org/stdlib/libdo...doc/index.html

Kind regards

robert
 
Reply With Quote
 
 
 
 
Alder Green
Guest
Posts: n/a
 
      03-22-2006
Hi

Iterate over OOO.csv's lines, split each line as you wish (probably
using slice notation is the easiest for fixed length columns), and
writing each slice into the desired destination file.

Regards,
Alder

On 3/22/06, (E-Mail Removed) <(E-Mail Removed)> wrote:
> Hello,
>
> Suppose "OOO.csv" is a data file with 9 columns, and I want to create a
> new file that is consisted of 2nd, 5th, and 7th columns of the OOO.csv
> (i.e., subset of the original), how do I do this?
>
> Thanks.
>
>
>



 
Reply With Quote
 
James Edward Gray II
Guest
Posts: n/a
 
      03-22-2006
On Mar 22, 2006, at 9:58 AM, (E-Mail Removed) wrote:

> Hello,
>
> Suppose "OOO.csv" is a data file with 9 columns, and I want to
> create a
> new file that is consisted of 2nd, 5th, and 7th columns of the OOO.csv
> (i.e., subset of the original), how do I do this?


My suggestion, if you don't mind using a non-standard library:

Neo:~/Desktop$ ls
000.csv trim_columns.rb
Neo:~/Desktop$ cat 000.csv
1,2,3,4,5,6,7,8,9
a,b,c,d,e,f,g,h,i
Neo:~/Desktop$ ruby -rubygems trim_columns.rb 000.csv
2,5,7
b,e,g
Neo:~/Desktop$ cat trim_columns.rb
#!/usr/local/bin/ruby -w

require "faster_csv"

FasterCSV.filter { |row| row.replace(row.values_at(1, 4, 6)) }

__END__

Hope that helps.

James Edward Gray II


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
TurboTax Basic vs. Taxcut Basic? Sharp Dressed Man Computer Support 1 01-12-2009 12:52 PM
What is the difference between Visual Basic.NET and Visual Basic 6? Jimmy Dean Computer Support 3 07-25-2005 07:05 AM
Re: Python interpreter in Basic or a Python-2-Basic translator. rrr@ronadam.com Python 0 05-02-2005 01:48 PM
Python interpreter in Basic or a Python-2-Basic translator. Engineer Python 6 05-01-2005 10:16 PM
Upgrading Microsoft Visual Basic 6.0 to Microsoft Visual Basic .NET Jaime MCSD 2 09-20-2003 05:16 AM



Advertisments