0
cat <file1>
name=HOST2
WWN=50.01.43.80.29.6A.84.82
WWN=50.01.43.80.29.6A.84.89
WWN=50.01.43.80.29.6A.84.8A
objectID=LU.R800.57488.43
objectID=LU.R800.57488.44
objectID=LU.R800.57489.44
name=HOST3
WWN=50.01.43.80.28.55.99.5C
WWN=50.01.43.80.28.55.99.5D
objectID=LU.R800.57488.45
objectID=LU.R800.57488.46
objectID=LU.R800.57488.47
objectID=LU.R800.5748A.47
name=HOST2
WWN=50.01.43.80.29.6A.84.87
WWN=50.01.43.80.29.6A.84.88
objectID=LU.R800.57486.41
objectID=LU.R800.57486.42
objectID=LU.R800.57486.43

I need output to be like this.

HOST2 50.01.43.80.29.6A.84.82 LU.R800.57488.43
HOST2 50.01.43.80.29.6A.84.82 LU.R800.57488.44
HOST2 50.01.43.80.29.6A.84.82 LU.R800.57489.44
HOST2 50.01.43.80.29.6A.84.89 LU.R800.57488.43
HOST2 50.01.43.80.29.6A.84.89 LU.R800.57488.44
HOST2 50.01.43.80.29.6A.84.89 LU.R800.57489.44
HOST2 50.01.43.80.29.6A.84.8A LU.R800.57488.43
HOST2 50.01.43.80.29.6A.84.8A LU.R800.57488.44
HOST2 50.01.43.80.29.6A.84.8A LU.R800.57489.44
HOST3 50.01.43.80.28.55.99.5C LU.R800.57488.45
HOST3 50.01.43.80.28.55.99.5C LU.R800.57488.46
HOST3 50.01.43.80.28.55.99.5C LU.R800.57488.47
HOST3 50.01.43.80.28.55.99.5C LU.R800.5748A.47
HOST3 50.01.43.80.28.55.99.5D LU.R800.57488.45
HOST3 50.01.43.80.28.55.99.5D LU.R800.57488.46
HOST3 50.01.43.80.28.55.99.5D LU.R800.57488.47
HOST3 50.01.43.80.28.55.99.5D LU.R800.5748A.47
HOST2 50.01.43.80.29.6A.84.87 LU.R800.57486.41
HOST2 50.01.43.80.29.6A.84.87 LU.R800.57486.42
HOST2 50.01.43.80.29.6A.84.87 LU.R800.57486.43
HOST2 50.01.43.80.29.6A.84.88 LU.R800.57486.41
HOST2 50.01.43.80.29.6A.84.88 LU.R800.57486.42
HOST2 50.01.43.80.29.6A.84.88 LU.R800.57486.43
0

Here is a straightforward perl script:

#!/usr/bin/perl -n
#

sub printall {
    foreach my $wwn (@wwns) {
        foreach my $obj (@objects) {
            print "$name $wwn $obj\n";
        }
    }
}

if (/name=(.*)/) {
    if ($name) {
        printall;
    }
    $name = $1;
    @wwns = ();
    @objects = ();
} elsif (/WWN=(.*)/) {
    push @wwns, $1;
} elsif (/objectID=(.*)/) {
    push @objects, $1;
}

END {
    printall;
}

It loops over the line in a file, collecting the WWNs and objectIds. Then, each time it meets a line with name= or the end of file, it prints what it has collected, in the order of your example.

  • appreciate your help. it worked perfectly. – Anesh Kumar Mar 15 '17 at 13:50
0

awk version:

#!/usr/bin/awk -f

function output(name,WWN,objectID) {
  for (x in WWN) {
    for (y in objectID) {
      print name, x, y;
    }
  }
}

BEGIN {
  FS = "=";
}

{
  if ($1=="name") {
    output(name,WWN,objectID);
    name = $2;
    delete WWN;
    delete objectID;
  }
  if ($1=="WWN") {WWN[$2]=$2}
  if ($1=="objectID") {objectID[$2]=$2}
}

END {output(name,WWN,objectID)}
  • I appreciate your help for awk version. it worked – Anesh Kumar Mar 15 '17 at 19:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.