SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Feb 2011
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Possible combination trick

    Let's say I have this:

    to you the dog
    to that the dog
    was to the dog
    and you the dog
    you and the dog
    and that the dog
    and he the dog
    he and the dog
    and was the dog

    and I want this

    to you and this
    to that and this
    was to and this
    and you and this
    you and and this
    and that and this
    and he and this
    he and and this
    and was and this

    How do you change every the dog to and this with a command. Then have it
    sent to a .rb without changing them manually one by one.

  2. #2
    Team ********* Louis Simoneau's Avatar
    Join Date
    Sep 2009
    Location
    Melbourne, Australia
    Posts
    228
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Sounds like you need the gsub function: http://www.ruby-doc.org/core/classes...g.html#M001186

  3. #3
    SitePoint Wizard
    Join Date
    Mar 2001
    Posts
    3,537
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ...then you write the changed lines to a new file, close the new file, delete the old file, and rename the new file to the old file name. You can use Tempfile to come up with a new filename that won't clash with any existing filenames.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •