Not sure if this is what you are looking for, but if you are trying
to search a file placing the lines that contain "Blah1" into a file
called "Blah1.csv", the lines containg "Blah2" into a file called
"Blah2.csv" etc, Rio might help:
require 'rio'
rio('filename.csv').chomp.lines(/Blah[^,]*/) do |line,m|
rio(m) + '.csv' << line + $/
end
Then again it might not.
···
On Aug 15, 10:18 pm, Michael Linfield <globyy3...@hotmail.com> wrote:
Alex Gutteridge wrote:
> On 16 Aug 2007, at 13:29, Michael Linfield wrote:
>> data from, then at the end of the program delete Blah1.csv ?
> Sure, use tempfile, but I think botp has shown why you don't really
> need the temporary file (unless there's part of this problem I'm not
> understanding):
the reason im going to use a tempfile is because thers going to be a
per'se blah2 blah3 ect. So im storing the grep from blah1, blah2, and
blah3 in different files so i can later pull the data from those files
to graph each line with ruport. each line will represent Blah1 Blah2
Blah3 ect. So unless i can shove the grep output into an array, and each
line be an element, ive gotta use a tempfile. Maybe theres a better way?
If thers a better approached im all ears
Thanks a ton btw, you all have been a tremendous help.
--
Posted viahttp://www.ruby-forum.com/.
/,+/ # matches one or more comma characters
/[z,]+/ # matches one or more z or comma characters intermixed
/[^,]+/ # matches one or more characters that aren't a comma
Read up on character classes in regexps.
···
On Aug 16, 11:23 am, Kaldrenon <kaldre...@gmail.com> wrote:
[...] I'm a little confused about how a pattern
like [^,]+ gets an element, given that (unless I'm mistaken) in a
standard regexp, it would only match on a string that contained a
series of commas that beginning of a line, like "," or "abc\n,".
What's my mistake/confusion here?
From: rio4ruby [mailto:Christopher.Kleckner@gmail.com]
# require 'rio'
# rio('filename.csv').chomp.lines(/Blah[^,]*/) do |line,m|
# rio(m) + '.csv' << line + $/
# end
simply amazing. btw, how does rio handle big files, does it load them
whole in memory?
thanks for rio.
kind regards -botp
it seems things have been amped a few levels of complication since my
first few post lol. The quote above might seem like the cleanest way to
do this, however if i use this method...ill still need the commas,
because when u take a csv and put it in simple text, the commas are what
seperate the columns. so maybe it should look something like this?
require 'rio'
rio('filename.csv').chomp.lines(/Blah1/) do |line,m|
rio(m) + '.csv' << line + $/
end
# > simply amazing. btw, how does rio handle big files, does it
# load them whole in memory?
# Never. Examples that assume I have a file small enough to load into
# memory irritate me.
You are right, that was a poorly thought out regular expression.
One could also use Rio's csv mode (which uses the stdlib csv):
rio('filename.csv').chomp.csv.records(/Blah\w*/) do |rec,m|
rio(m.to_s + '.csv').csv << rec
end
But this also is definately NOT a robust solution.
···
On Aug 16, 1:43 pm, Michael Linfield <globyy3...@hotmail.com> wrote:
Peña, Botp wrote:
> From: rio4ruby [mailto:Christopher.Kleck...@gmail.com]
> # require 'rio'
> # rio('filename.csv').chomp.lines(/Blah[^,]*/) do |line,m|
> # rio(m) + '.csv' << line + $/
> # end
> simply amazing. btw, how does rio handle big files, does it load them
> whole in memory?
> thanks for rio.
> kind regards -botp
it seems things have been amped a few levels of complication since my
first few post lol. The quote above might seem like the cleanest way to
do this, however if i use this method...ill still need the commas,
because when u take a csv and put it in simple text, the commas are what
seperate the columns. so maybe it should look something like this?
require 'rio'
rio('filename.csv').chomp.lines(/Blah1/) do |line,m|
rio(m) + '.csv' << line + $/
end
###