From: "Jesús Gabriel y Galán" Date: 2011-05-11T17:00:00+09:00 Subject: Re: gsub and multiple-replacement On Wed, May 11, 2011 at 2:49 AM, Greg Hacke wrote: > 7stud -- wrote in post #997852: > > OK, I think it would be better to be a bit more specific... > > User logs into site. Credentials are verified via LDAP. > > At login, I am copying a .mobileconfig template file (xml/plist) and > saving it as {username}.profile.mobileconfig > This file contains placeholders for: >  {username} = bob@domain.tld >  {userroot} = bob >  {password} = mypassword > > I need to read it, modify it, save it and replace it. At that point, the > user will get the index and be afforded to download this file. > > Thoughts? How big is the file? Is it acceptable to have it all in memory? Do you have control over the format of the placeholders? If so, I'd go with Philip's suggestion of using ERB. Just change {username} to <%= username %> and evaluate the template with a binding that contains a variable username. For example: username = "Bob" password = "pwd" expanded_file = ERB.new(File.read("template.erb"), nil, "%<>").result(binding) template.erb: The user is <%= username %> The password is <%= password %> Jesus.