unterminated string meets end of file

D

div n

Tried the following script on MAC os using ruby , but i get the following error

#$LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/../..')
#$LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/../../lib')

require 'rubygems'
require 'yajl'
require 'json-compare'

files = Dir.glob("../Downloads/Emailing__a/b.json")
@original_string_or_regex = "\""
@replacement_string = """

text = File.read(files)
puts = text.gsub(/@original_string_or_regex/, @replacement_string)
File.open(filename, 'rw') { |file| file << puts }

but i get the following error.
unterminated string meets end of file

can anyone suggest on how to fix this?
 
D

div n

Thanks Andi.Helped me resolve the issue.

I would also like to know in the following what should i put in order to replace ." with a blank space or empty space in the file ?

@original_string_or_regex = ".""
@replacement_string = ""
 
A

Andi Altendorfer

Thanks Andi.Helped me resolve the issue.



I would also like to know in the following what should i put in order to replace ." with a blank space or empty space in the file ?



@original_string_or_regex = ".""

@replacement_string = ""

puts 'some." string'.gsub(/(\s+)?\.\"/, ' ').gsub(/\ +/,' ')
# => some string

The first gsub replaces any number of spaces followed by ." with a single space.
The second gsub replaces multiple spaces by a single space.

cheers
- Andi
 
S

Simon Krahnke

* Andi Altendorfer said:
puts 'some." string'.gsub(/(\s+)?\.\"/, ' ').gsub(/\ +/,' ')

What are parentheses for? And the question mark? /\s*\.\"/?
# => some string

The first gsub replaces any number of spaces followed by ." with a single space.
The second gsub replaces multiple spaces by a single space.

mfg, simon .... l
 
R

Robert Klemme

What are parentheses for? And the question mark? /\s*\.\"/?

And why escape a double quote in a regexp? And what about following spaces?

irb(main):002:0> 'some." string'.gsub(/\s*\."\s*/, ' ')
=> "some string"

Cheers

robert
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top