Hi all,
I'm new to Ruby and pretty new to programming in general. My limited
prior experience is with JavaScript, so I'm not accustomed to handling
file I/O or working with Unix/Terminal. I'm working on a script that
takes a large quantity of text copied from a web browser and does some
reformatting so the result lines up neatly in a CSV and eventually a
spreadsheet. Basically, I'm using a few regex/gsub statements to remove
unnecessary text from the beginning of the page and to add/remove tabs
from certain places. I've got two issues with this script, please see
the attached files.
1. Right now, I can run the script in Terminal and direct the output to
a new file and everything works (except for one of the regexes, see #2
below), provided that I first save the text in a file that matches the
file name used in the script. If possible, I'd prefer to skip saving a
file with the input text and allow the user to simply copy and paste it
directly into Terminal. In other words, you could run the script in
Terminal, be prompted to paste your text in, and the script would make
all
the necessary changes to the text and output to a file. I tried adding
a prompt and gets statement to hold the text in a variable, but this
just grabs a single line of text, terminates the Ruby script, and then
produces a Terminal error for each subsequent line. Is there any way I
can accomplish this alternate behavior?
2. The regex I created to remove all unneeded content isn't working. I
checked this in Rubular and it worked as I expected, but it does not
work when I run the script. All the content that is needed in the
output follows a unique set of table headers on the web page, so I
should be able to find everything leading up to and including those
headers and remove it. The regex looks like this (with random terms
added in place of the table headers):
/.*hat\.goat\sthis thing\sthat thing\sstuff\scheese/m
As it is, the headers do get replaced, but the content that precedes it
does not. I get the same result if I remove the wildcard at the
beginning of the regex. Any ideas?
Attachments:
http://www.ruby-forum.com/attachment/8432/test_forum.rb
http://www.ruby-forum.com/attachment/8433/input.txt
···
--
Posted via http://www.ruby-forum.com/.