Friday 15 June 2012

shell - Use map or dictionary to find value -


This is my position. I have an array of device IDs, I know what device id with which IP addresses are I want to use the Device ID to find the correct ID address and pass them both in one order. I am using a shell script to do this.

Here's some psuedo code for everything I want to do.

This is not my special type of IP address, IP address: ID: IP ID: IP ID: IP)

My ID of the ID is that I am using in a particular order

Maybe create an array of objects with two properties (id and IP) for each ID

  array_of_used_ids = (id id id) <>  for array_object (int i = 0; i   

to id Then I want (ie I = 0; i & lt; count; i ++) with {./command} to run all the commands in a loop (or whatever you recommend for) < / P>

  in array_of_used_ids ./run_this_command for id Array_object [i] .ip array_object [i] .id}    

you already have Build primary arrays, so make a regex from the used ID

  r Egex = "^ $ {array_of_used_ids [0]}:" I = 1 while [$ i -lt $ {# array_of_used_ids [ *]}]; "Regex =" $ regex | ^ $ {Array_of_used_ids [$ i]}: "I = $ (($ i + 1))   

This will give you" regex "Id: | ^ id: | ^ id:" Then Match your dictionary again when checking against regex, when separated ':' with the space:

  array_object = () i = 0 J = 0 while [$ i-lt $ {# Dictionary_thing [*]}]; If [[$ word_thing [$ i] = ~ $ regex]]; If array_object [$ j] = $ {dictionary_thing [$ i] /: /} #If the ID is possible to include ':', then you need a different method for division here j = $ (( Finally, repeat your result object and execute the command  
  i = 0 while [$ i -lt $ {# Array_object [*]}]; command_to_excut $$ {array_object [$ i]} i = $ ((i $ 1 +)) done    

No comments:

Post a Comment