Need a hand on the split command in Chef / Ruby or a regex...

Posted on 2016-08-09
Medium Priority
Last Modified: 2016-08-15
I am using Chef / Ruby and I am using two environments 0001 and 0002..I have 2 log files that I want to lay down on two nodes on in each environment, so hope I make sense here.  I need to hopefully use split in Ruby to parse the 0001 / 0002 and determine which log file to lay down - one in 0001 and 0002 for the other, here is what I have in the configure.rb file:

environment_id = node[:chef_environment].split()

Log file names:



If I didn't give enough detail pls let me know.
Question by:Harper McDonald
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4

Author Comment

by:Harper McDonald
ID: 41749511

the node[:chef_environment].split()

should only return 0001 or 0002 and of course be put into environment_id

Author Comment

by:Harper McDonald
ID: 41749544
Getting this now:

irb(main):006:0> log3.split("gryphon_cwis_sdlc_")
=> ["", "0002"]

Just need to remove the [ " and ,  --- any ideas?
LVL 35

Expert Comment

by:Dan Craciun
ID: 41750278
Can you please provide the values of "node[:chef_environment]" and "$" ?

From the manual:
split(pattern=$;, [limit]) → anArray
Divides str into substrings based on a delimiter, returning an array of these substrings.

If pattern is omitted, the value of $; is used. If $; is nil (which is the default), str is split on whitespace as if ` ‘ were specified.

Accepted Solution

Harper McDonald earned 0 total points
ID: 41750452
nitro_environment_id = node[:chef_environment].split(//).last(4).join

I think I just found it out...

Author Closing Comment

by:Harper McDonald
ID: 41756116
Found out experimenting

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Make the most of your online learning experience.
This article will show how Aten was able to supply easy management and control for Artear's video walls and wide range display configurations of their newsroom.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
Suggested Courses

719 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question