tags:

views:

10

answers:

0

I want to append a heredoc string after a specific heredoc string if file doesn't contain it already.

Eg.

Here are 2 files:

# file1
Description:
  I am a coder
Username: user1
Password: password1

# file2
Description:
  I am a coder
Username: user2
Password: password2
Address:
  Email: [email protected]
  Street: user street 19 A

I want to add:

Address:
  Email: [email protected]
  Street: user street 19 A

if file doesn't contain it already, and after:

Description:
  I am a coder

So in the above files it will be added to the first one only. and that file will then look like this:

# file1
Description:
  I am a coder
Address:
  Email: [email protected]
  Street: user street 19 A
Username: user1
Password: password1

How could I do this in Ruby?