TStanley has asked for the wisdom of the Perl Monks concerning the following question:

I am writing a shell script to get the status of the logical volumes on an HP server. The command that I am using is lvdisplay, and it produces the following output:
$ lvdisplay /dev/vg00/lvol3 --- Logical volumes --- LV Name /dev/vg00/lvol3 VG Name /dev/vg00 LV Permission read/write LV Status available/syncd Mirror copies 1 Consistency Recovery MWC Schedule parallel LV Size (Mbytes) 200 Current LE 50 Allocated PE 100 Stripes 0 Stripe Size (Kbytes) 0 Bad block off Allocation strict/contiguous IO Timeout (Seconds) default
The above is more info than I really need. What I would like to get this to look like is the following:
LV Name /dev/vg00/lvol3 LV Status available/syncd Mirror copies 1
My attempt at this is to pipe the output of the lvdisplay into a perl command line program as follows:
lvdisplay /dev/vg00/lvol3 |perl -a -n -F'\n' -e'print "$F[1]\n$F[4]\n$ +F[5]\n";'
Any ideas as to how I might accomplish this?

TStanley
--------
The only thing necessary for the triumph of evil is for good men to do nothing -- Edmund Burke

Replies are listed 'Best First'.
Re: Parsing command line input from STDIN
by broquaint (Abbot) on Dec 19, 2003 at 14:01 UTC
    If you're field names are going to stay static then this should do the trick
    lvdisplay /dev/vg00/lvol3 | \ perl -ne 'print if /LV (Name|Status)|Mirror/'
    HTH

    _________
    broquaint

      That did the trick. Thanks for the help. :-D

      TStanley
      --------
      The only thing necessary for the triumph of evil is for good men to do nothing -- Edmund Burke
Re: Parsing command line input from STDIN
by thospel (Hermit) on Dec 19, 2003 at 16:33 UTC
    Broqaints answer is of course the proper one, but in case you really wanted to select numbered lines, you can use an impossible output character to slurp all:
    lvdisplay /dev/vg00/lvol3 | perl -ln0aF'\n' -e 'print for @F[1,4,5]'
    (or use -0777 if there are no impossible output characters). Golfers (sorry, I can't resist) might write:
    lvdisplay /dev/vg00/lvol3 | perl -lp0aF'\n' -e '}for(@F[1,4,5]){' lvdisplay /dev/vg00/lvol3 | perl -n0aF/^/m -e 'print@F[1,4,5]'
    Or select on line-number, e.g.:
    lvdisplay /dev/vg00/lvol3 | perl -ne 'print if $.=~/^(2|5|6)$/'
    Golfers would of course write that as:
    lvdisplay /dev/vg00/lvol3 | perl -pe '$_ x=$.=~/^[256]/' lvdisplay /dev/vg00/lvol3 | perl -pe '$_ x=256=~$.' lvdisplay /dev/vg00/lvol3 | perl -pe '$_ x=$^H=~$.'
    (use a real control-H in the last one for a one char gain)
Re: Parsing command line input from STDIN
by gt8073a (Hermit) on Dec 19, 2003 at 22:17 UTC
    I am writing a shell script to...
    lvdisplay /dev/vg00/lvol3 | grep -P "LV (Name|Status)|Mirror"
    Still Perl, I suppose.

    Will perl for money
    JJ Knitis