Sponsored Content
Top Forums Programming problems iterating in RUBY while extracting info from YAML, Pls help! Post 302243433 by fpmurphy on Sunday 5th of October 2008 02:38:32 PM
Old 10-05-2008
Yes, one of your problems is the repeated calls to yaml.keys.first. (will always return 'notsoconfi')

The following code delivers the expected output:
Code:
require 'yaml'

set_tpl = '-l {device} -L={mode} -P={policy} '

yaml = YAML::load(File.open("testyaml.yaml"))

yaml.each do |name, option|
   if option['type'] == "aggr"
      tpl = 'dladm create-{type} {sets} {cmd}'
      tpl.gsub! '{type}', option['type']
      tpl.gsub! '{cmd}', name

      sets = ""
      yaml[name]['device'].each do |device|
         set = set_tpl.dup
         set.gsub! '{device}', device[0]
         set.gsub! '{mode}',   device[1]['mode']
         set.gsub! '{policy}', device[1]['policy'].join(',')
         sets << set
      end

      tpl.gsub! '{sets}', sets
      puts tpl.gsub(/\s+/,' ')
   end
end

Code:
dladm create-aggr -l vnic9 -L=off -P=L2,L3 -l vnic3 -L=active -P=L2,L3 -l vnic6 -L=active -P=L3,L2 notsoconfi
dladm create-aggr -l vnic1 -L=active -P=L2 -l vnic2 -L=active -P=L3,L4 confivnic

 

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

extracting info from Unix database to construct a visual diagram

Ok heres the situation, We use Solaris 8 at work with Sybase for the db. I need to be able to easily create visual diagrams of some of our more complex systems. I've been using Visio which is such a manual process and takes a while. I was thinking maybe using Visio somehow in conjunction... (0 Replies)
Discussion started by: fusion99
0 Replies

2. UNIX for Dummies Questions & Answers

Extracting Info

i have a file that contain lines like this 9.4.7.8.5.7.9.0.5.7.1.2.msisdn.sub.cs. 1 IN CNAME SDP01.cs. there are about 50,000 lines like this in the files i want to the extract the digits from the above line like:- 947857905712 OS Solaris9 (3 Replies)
Discussion started by: muneebr
3 Replies

3. UNIX for Dummies Questions & Answers

Extracting specific info from finger command

Hello all, my unix is bash based and the finger command output is: Login Name Tty Idle LoginTime Office amos.john Amos John pts/26 1 Dec 5 16:18 (77.100.22.07) What am trying to achieve is extract the Login (amos.john) and Name (Amos John) from this output without using awk or sed. ... (1 Reply)
Discussion started by: franny
1 Replies

4. UNIX for Dummies Questions & Answers

Extracting spec info from finger.

Hi everyone, I'm trying to extract the user name and full name from the finger command without using sed or awk. Any pointers? Thanks in advance. (6 Replies)
Discussion started by: franny
6 Replies

5. Shell Programming and Scripting

Parsing file, yaml file? Extracting specific sections

Here is a data file, which I believe is in YAML. I am trying to retrieve just the 'addon_domains" section, which doesnt seem to be as easy as I had originally thought. Any help on this would be greatly appreciated!! I have been trying to do this in awk and mostly bash scripting instead of perl... (3 Replies)
Discussion started by: Rhije
3 Replies

6. Shell Programming and Scripting

matching and extracting info from text files

Hi all, I have two .txt file i.e. First text file: 2 4 1 4 Second text file 2 1.nii.gz 4 334.nii.gz 1 12.nii.gz 4 134.nii.gz If entry in 1st column of 1st text file matches the 1st column of 2nd text file, then copy the file (name of which is the second column) associated with... (4 Replies)
Discussion started by: vd24
4 Replies

7. Web Development

Permission problems calling Ruby from php script

I'm just getting my feet wet with web development, so hopefully this is a simple thing I'm overlooking, but so far I'm stumped. I have a php script that calls Ruby via exec(). This works fine in my test environment, but when I moved it to my production environment I run into a permissions... (7 Replies)
Discussion started by: dantes990
7 Replies

8. Solaris

Extracting HBA Card Hardware info

Hello, I am very new to solaris so please bear with me. I have 2 machines in question. For both I am trying to get the HBA Card Hardware information such as: HBA Model Name HBA Firmware version HBA Port details HBA Driver details First machine is a Solaris 10. When I execute fcinfo... (6 Replies)
Discussion started by: flagman5
6 Replies

9. UNIX for Dummies Questions & Answers

Extracting specific info finger command

how to extract user machine name for current terminal using finger command below command gives machinename for all session , is it possible to filter it to only currernt terminal ? finger -b -p $LOGNAME | grep from (12 Replies)
Discussion started by: lalitpct
12 Replies

10. Shell Programming and Scripting

Have a situation while extracting info

i have a text file which i am generating from few sqls. format is like : col1 col2 col3 col4 col5 1001 DONE ABC 17-sep-14 12:02:05 1001 DONE ABC 17-sep-14 12:02:05 1001 DONE ABC 17-sep-14 12:02:55 1001 REDONE ABC ... (6 Replies)
Discussion started by: deepakiniimt
6 Replies
Parse::CPAN::Meta(3pm)					 Perl Programmers Reference Guide				    Parse::CPAN::Meta(3pm)

NAME
Parse::CPAN::Meta - Parse META.yml and other similar CPAN metadata files SYNOPSIS
############################################# # In your file --- rootproperty: blah section: one: two three: four Foo: Bar empty: ~ ############################################# # In your program use Parse::CPAN::Meta; # Create a YAML file my @yaml = Parse::CPAN::Meta::LoadFile( 'Meta.yml' ); # Reading properties my $root = $yaml[0]->{rootproperty}; my $one = $yaml[0]->{section}->{one}; my $Foo = $yaml[0]->{section}->{Foo}; DESCRIPTION
Parse::CPAN::Meta is a parser for META.yml files, based on the parser half of YAML::Tiny. It supports a basic subset of the full YAML specification, enough to implement parsing of typical META.yml files, and other similarly simple YAML files. If you need something with more power, move up to a full YAML parser such as YAML, YAML::Syck or YAML::LibYAML. Parse::CPAN::Meta provides a very simply API of only two functions, based on the YAML functions of the same name. Wherever possible, identical calling semantics are used. All error reporting is done with exceptions (die'ing). FUNCTIONS
For maintenance clarity, no functions are exported. Load my @yaml = Load( $string ); Parses a string containing a valid YAML stream into a list of Perl data structures. LoadFile my @yaml = LoadFile( 'META.yml' ); Reads the YAML stream from a file instead of a string. SUPPORT
Bugs should be reported via the CPAN bug tracker at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Parse-CPAN-Meta <http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Parse-CPAN-Meta> AUTHOR
Adam Kennedy <adamk@cpan.org> SEE ALSO
YAML, YAML::Syck, Config::Tiny, CSS::Tiny, <http://use.perl.org/~Alias/journal/29427>, <http://ali.as/> COPYRIGHT
Copyright 2006 - 2009 Adam Kennedy. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. The full text of the license can be found in the LICENSE file included with this module. perl v5.12.1 2010-04-26 Parse::CPAN::Meta(3pm)
All times are GMT -4. The time now is 04:27 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy