scripting help (215 Views)
Trusted Contributor
Posts: 385
Registered: ‎06-06-2003
Message 1 of 2 (215 Views)

scripting help



I'd like some help with a script


I have a file with the following data


         Device                 Product                   Device
---------------------- --------------------------- ---------------------
Name            Type   Vendor    ID           Rev  Ser Num      Cap (KB)
---------------------- --------------------------- ---------------------
/dev/sdbc       M(2)   EMC       SYMMETRIX    5876 110265D000   17677440
/dev/sdbd       M(3)   EMC       SYMMETRIX    5876 110265F000   53032320
/dev/sdbe       M(2)   EMC       SYMMETRIX    5876 1102705000   17677440
/dev/sdbf              DGC       RAID 5       0326 8600001D     62914560
/dev/sdbg              DGC       RAID 5       0326 8D0000AA    199229440
/dev/sdbh              DGC       RAID 5       0326 09000028     26214400
/dev/emcpoweraa        DGC       RAID 5       0326 8600001D     62914560

some lines have 6 fields and other lines have seven fields


I execute the pvs command and I want to search each lun from the EMC output and depending on the number of fields to determine what to print


  PV             VG           Fmt  Attr PSize   PFree
  /dev/emcpowerm emcvg        lvm2 a-    67.43G      0
  /dev/emcpowero VG1          lvm2 a-    16.86G  11.86G
  /dev/emcpowerp bc2eoaipp1vg lvm2 a-    50.57G   8.57G
  /dev/sda2      systemvg     lvm2 a-    33.59G      0
  /dev/sdad      emcvg        lvm2 a-    67.43G 428.00M


so I have come up with 


cat /tmp/pvs |awk 'NR>1 {sub("\/dev\/","",$1);print $1,$2,$5}' |while read PV VG PSZ


        awk -v search=${PV} '$0 ~ search {if (line != "") print line; line =$NF} {if(NF==6) {line=$1":"$4":"$5":"$NF}} {if(NF==7) {line=$1":"$5":"$6":"$NF}};END{print line}' /tmp/




it doesnt quite work because the output is the same



can someone help out with the syntax please :)





Honored Contributor
Posts: 1,449
Registered: ‎12-05-2002
Message 2 of 2 (195 Views)

Re: scripting help



it's not a syntax issue, it's a logic issue.


For the sample data files provided, none of your lines match this line:


$0 ~ search


However for each line from the "/tmp/" file, the last line matches this check:




As such, "END{print line}" always prints the last line from that file.


You will want to revisit your logic.




The opinions expressed above are the personal opinions of the authors, not of HP. By using this site, you accept the Terms of Use and Rules of Participation.