Link to home
Start Free TrialLog in
Avatar of MatthewF
MatthewFFlag for Afghanistan

asked on

Regular Expression: get third field and only single instances

I need a   Regular Expression to add to the following

$mediaServerName = ($storageUnit =~

that will pull put the third line and place only single instances of the same field into the array. The $storageUnit  looks like:


STK9310_L00_DB00D02 2 db00d02 1 0 6 1 0 "*NULL*" 0 8 2000 *NULL*  
STK9310_L00_DB00M01 2 db00m01 1 0 6 4 0 "*NULL*" 0 2 2000 *NULL*  
STK9310_L00_DB00M01 2 db00m01 1 0 6 1 0 "*NULL*" 0 8 2000 *NULL*  

and I would like for the array to have db00d02 and db00m01.


NOT: db00d02 ,db00m01 and db00m01
Avatar of leflon
leflon
Flag of Germany image

Hi MatthewF,
you can use a hash to ensure there is only a single instance

%hsh;
while(<>) {
  @line =split;
  if ( not $hsh{$line[0]}) {
    $hsh{$line[0]} = $line[2];
}

now you can traverse the hash and do what you like with it (store it in an array, print it etc.)

hth
leflon
ASKER CERTIFIED SOLUTION
Avatar of ozo
ozo
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial