Help with List Variable

  • Hi, 

    Please could anyone help me with following requirement. I have output like below -

    ID Name
    1 {a,b,c}
    2 {c,d,e}
    3 {a,e}
    4 {b,d,f}
    5 {a,d,f,g}

    Is it possible to manipulate it to output like

    ID Name
    1 a
    1 b
    1 c
    2 c
    2 d
    2 e
    3 a
    3 e
    4 b
    4 d
    4 f
    5 a
    5 d
    5 f
    5 g

    Any input is greatly appreciated.

    Regards,
    Renuka

    [font="Verdana"]Renuka__[/font]

  • No idea what you are working with so how you do it is impossible to say. However, you can use substring in Powershell. The following returns just the letter a:
    $Name = '{a,b,c}'
    $Name.Substring(1,1)

    Maybe play around with that to see if you can get the desired output. 

    Sue

  • it is possible. but you haven't given enough details to give you a working solution.

    assuming you have a list of pairs as per your input you would do a foreach loop
    foreach ($item in $items)
    {
      $splits = $item("Name").replace("{","").replace("}","").split(",")
      foreach ($split in $splits)
     {
       $record = $split|select {N="ID", e=$item{"ID")}, $_.Name
       $record
     }
    }
    there are syntax errors above - but the logic could be like it

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply