Operating System - HP-UX
1745788 Members
3520 Online
108722 Solutions
New Discussion

Re: Printing formatted output

 
SOLVED
Go to solution
lawrenzo
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
2 REPLIES 2
Dennis Handly
Acclaimed Contributor
Solution

Re: Printing formatted output

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

lawrenzo
Trusted Contributor

Re: Printing formatted output

thanks Dennis

 

that will give me a start :)

 

Chris

hello