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
Solved

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

Posted on 2016-08-09
5
51 Views
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:

cwis_sdlc_0001.log

cwis_sdlc_0002.log

If I didn't give enough detail pls let me know.
0
Comment
Question by:Harper McDonald
  • 4
5 Comments
 
LVL 4

Author Comment

by:Harper McDonald
ID: 41749511
UPDATE:

the node[:chef_environment].split()

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

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?
0
 
LVL 34

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.
0
 
LVL 4

Accepted Solution

by:
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...
0
 
LVL 4

Author Closing Comment

by:Harper McDonald
ID: 41756116
Found out experimenting
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
backup program with robocopy 6 42
What's wrong with this PDO query? 5 27
mysql query for sum() 3 28
Regex - Capture everything between two strings. 8 6
These days socially coordinated efforts have turned into a critical requirement for enterprises.
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

792 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