Languages and Scripting
Showing results for 
Search instead for 
Do you mean 

Printing formatted output

SOLVED
Go to Solution
Trusted Contributor Trusted Contributor

Printing formatted output

Hi All


 

I want to print a colon delimited output from the following file

 

Pseudo name=hdiskpower586
   0 fscsi0                   hdisk1437 SP A5     active  alive       0      0
   0 fscsi0                   hdisk1474 SP B4     active  alive       0      0
   2 fscsi4                   hdisk1556 SP B5     active  alive       0      0
   2 fscsi4                   hdisk1566 SP A4     active  alive       0      0
Pseudo name=hdiskpower577
   0 fscsi0                   hdisk1465 SP B4     active  alive       0      0
   2 fscsi4                   hdisk1547 SP B5     active  alive       0      0
   2 fscsi4                   hdisk1557 SP A4     active  alive       0      0
   0 fscsi0                   hdisk832  SP A5     active  alive       0      0
Pseudo name=hdiskpower578
   0 fscsi0                   hdisk1429 SP A5     active  alive       0      0
   0 fscsi0                   hdisk1466 SP B4     active  alive       0      0
   2 fscsi4                   hdisk1548 SP B5     active  alive       0      0
   2 fscsi4                   hdisk1558 SP A4     active  alive       0      0
Pseudo name=hdiskpower579
   0 fscsi0                   hdisk1430 SP A5     active  alive       0      0
   0 fscsi0                   hdisk1467 SP B4     active  alive       0      0
   2 fscsi4                   hdisk1549 SP B5     active  alive       0      0
   2 fscsi4                   hdisk1559 SP A4     active  alive       0      0
Pseudo name=hdiskpower580
   0 fscsi0                   hdisk1431 SP A5     active  alive       0      0
   0 fscsi0                   hdisk1468 SP B4     active  alive       0      0
   2 fscsi4                   hdisk1550 SP B5     active  alive       0      0
   2 fscsi4                   hdisk1560 SP A4     active  alive       0      0

I need the above output to appear as

 

hdiskpower586:hdisk1437:hdisk1474:hdisk1556:hdisk1566

 

hdiskpower being the device and hdisk being the path to each hdiskpower device

 

thanks

 

Chris

hello
1 ACCEPTED SOLUTIONS
Acclaimed Contributor Acclaimed Contributor

Re: Printing formatted output

[ Edited ]

Something like:

awk '

BEGIN { save = "" }

$1 ~ "Pseudo" {  # get device name

   if (save != "") print save # previous

   save = substr($2, 6)

   next

}

{

save = save ":" $3 # add path

}

END {

if (save != "") print save

}' input-file

2 REPLIES
Acclaimed Contributor Acclaimed Contributor

Re: Printing formatted output

[ Edited ]

Something like:

awk '

BEGIN { save = "" }

$1 ~ "Pseudo" {  # get device name

   if (save != "") print save # previous

   save = substr($2, 6)

   next

}

{

save = save ":" $3 # add path

}

END {

if (save != "") print save

}' input-file

Trusted Contributor Trusted Contributor

Re: Printing formatted output

thanks Dennis

 

that will give me a start :)

 

Chris

hello