On Sun, 4 Feb 2007, Drew O. wrote:
Where shall the result of that splitting reside? Also on the same unix
box where the original CSV document resides?
Regards
Thomas
Yes, I’d like the split files to be on the unix box as well. Obviously,
the easy solution is to install rails but I can’t (client paranoid,
etc). I do have ksh or perl to work with, but I have a working ruby
script which i’d like to use. Any other ideas?
installing rails would be a twenty ton sledgehammer approach.
ruby uses stdin if no script is provided. you need to send the script
to ruby
on stdin via ssh and let it process the local file, creating local
output.
here’s the code
harp:~ > cat a.rb
input = ARGV.shift
output = “#{ input }.out”
open(output, ‘w’) do |fd_out|
open(input) do |fd_in|
fd_in.each do |line|
fd_out.puts line.split(’,’).inspect
end
end
end
here is the remote file
harp:~ > ssh fortytwo.merseine.nu cat foo.csv
1,2,3
a,b,c
we spawn ruby on the remote host reading from stdin, giving ‘foo.csv’ as
an argument and the file’a.rb’ as the script to run
harp:~ > ssh fortytwo.merseine.nu ruby - foo.csv < a.rb
this works as expected: the output is created on the remote host
harp:~ > ssh fortytwo.merseine.nu cat foo.csv.out
[“1”, “2”, “3\n”]
[“a”, “b”, “c\n”]
hth.
-a