How do I extract a field between two other fields?

How do I extract a field between two other fields?

Post by Bryan Kelle » Wed, 27 Nov 1996 04:00:00



given a file like so:
 VG Name                /dev/vg03
   PV Name                /dev/dsk/c0d0s2
VG Name                /dev/vg01
   PV Name                /dev/dsk/c1d0s2
VG Name                /dev/vg00
   PV Name                /dev/dsk/c2d0s2
VG Name                /dev/vg02
   PV Name                /dev/dsk/c3d0s2
VG Name                /dev/vg07
   PV Name                /dev/dsk/c6d0s2
VG Name                /dev/vg05
   PV Name                /dev/dsk/c7d0s2
VG Name                /dev/vg06
   PV Name                /dev/dsk/c8d0s2
VG Name                /dev/vg04
   PV Name                /dev/dsk/c9d0s2

I need to extract the PV field(s) between the VG Name field(not including
the VG Name field) as there could be more than one PV Name field per volume
group.

I am not sure of how to do this, I am assuming that grep,awk, or sed is
involved Would anyone be as so kind as to provide me with a snippet of code
that may produce the output that I want?
Any help would be greatly appreciated!!

 
 
 

How do I extract a field between two other fields?

Post by Cal Duniga » Wed, 27 Nov 1996 04:00:00



Quote:> given a file like so:
>  VG Name                /dev/vg03
>    PV Name                /dev/dsk/c0d0s2
> VG Name                /dev/vg01
>    PV Name                /dev/dsk/c1d0s2
> VG Name                /dev/vg00
>    PV Name                /dev/dsk/c2d0s2
> VG Name                /dev/vg02
>    PV Name                /dev/dsk/c3d0s2
> VG Name                /dev/vg07
>    PV Name                /dev/dsk/c6d0s2
> VG Name                /dev/vg05
>    PV Name                /dev/dsk/c7d0s2
> VG Name                /dev/vg06
>    PV Name                /dev/dsk/c8d0s2
> VG Name                /dev/vg04
>    PV Name                /dev/dsk/c9d0s2

> I need to extract the PV field(s) between the VG Name field(not including
> the VG Name field) as there could be more than one PV Name field per volume
> group.

Are the PV fields on a line by themselves?
    grep "^ *PV" infile

\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

     Consulting                    a world where Ken Thompson is a
     Modeling                      relative unknown and Bill Gates is
     Training                      a famous billionaire.
//////////////////////////////////////////////////////////////////////

 
 
 

How do I extract a field between two other fields?

Post by Anthony Vigilant » Thu, 28 Nov 1996 04:00:00




> > given a file like so:
> >  VG Name                /dev/vg03
> >    PV Name                /dev/dsk/c0d0s2
> > VG Name                /dev/vg01
> >    PV Name                /dev/dsk/c1d0s2
> > VG Name                /dev/vg00
> >    PV Name                /dev/dsk/c2d0s2
> > VG Name                /dev/vg02
> >    PV Name                /dev/dsk/c3d0s2
> > VG Name                /dev/vg07
> >    PV Name                /dev/dsk/c6d0s2
> > VG Name                /dev/vg05
> >    PV Name                /dev/dsk/c7d0s2
> > VG Name                /dev/vg06
> >    PV Name                /dev/dsk/c8d0s2
> > VG Name                /dev/vg04
> >    PV Name                /dev/dsk/c9d0s2

> > I need to extract the PV field(s) between the VG Name field(not including
> > the VG Name field) as there could be more than one PV Name field per volume
> > group.

> Are the PV fields on a line by themselves?
>     grep "^ *PV" infile

> \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

>      Consulting                    a world where Ken Thompson is a
>      Modeling                      relative unknown and Bill Gates is
>      Training                      a famous billionaire.
> //////////////////////////////////////////////////////////////////////

I forgot to mention one other detail, I have to associate the PV fields
with the VG field above it.
 
 
 

How do I extract a field between two other fields?

Post by Patrice Alla » Thu, 28 Nov 1996 04:00:00



>given a file like so:
> VG Name                /dev/vg03
>   PV Name                /dev/dsk/c0d0s2
>VG Name                /dev/vg01
>   PV Name                /dev/dsk/c1d0s2
>I need to extract the PV field(s) between the VG Name field(not including
>the VG Name field) as there could be more than one PV Name field per volume
>group.

What about :

awk -F"[ \t]+" '/PV Name/ {print $4;}' FILENAME

Hope this helps,
Patrice.

----------------------------------------------------------------------

|  #include <disclaimer.h>  | V-mail : (+33) [0]4 92 29 39 49 + 3902 |
----------------------------------------------------------------------

 
 
 

How do I extract a field between two other fields?

Post by Adam Lovic » Fri, 29 Nov 1996 04:00:00




Quote:>given a file like so:
> VG Name                /dev/vg03
>   PV Name                /dev/dsk/c0d0s2
>VG Name                /dev/vg01
>   PV Name                /dev/dsk/c1d0s2
>I need to extract the PV field(s) between the VG Name field(not including
>the VG Name field) as there could be more than one PV Name field per volume
>group.

Awk is ideal for this kind of thing.

/VG Name/ {
        print vgname, pvlist # this will print blank for the first line
        vgname = $NF # set a variable for the VG
        next

Quote:}

{ pvlist = sprintf("%s %s", pvlist, $NF) } # build a list of PVs
END { print vgname, pvlist } # don't forget the last one!

This will print the Volume Group device, followed by a line of PV names.
It doesn't do any checking for blank lines but it might give a pointer
or two.

Good luck.
--
Adam Lovick

 
 
 

How do I extract a field between two other fields?

Post by Joseph McCaughan cont » Fri, 20 Dec 1996 04:00:00


: >

: >
: > > given a file like so:
: > >  VG Name                /dev/vg03
: > >    PV Name                /dev/dsk/c0d0s2
: > > VG Name                /dev/vg01
: > >    PV Name                /dev/dsk/c1d0s2
: > > VG Name                /dev/vg00
: > >    PV Name                /dev/dsk/c2d0s2
: > > VG Name                /dev/vg02
: > >    PV Name                /dev/dsk/c3d0s2
: > > VG Name                /dev/vg07
: > >    PV Name                /dev/dsk/c6d0s2
: > > VG Name                /dev/vg05
: > >    PV Name                /dev/dsk/c7d0s2
: > > VG Name                /dev/vg06
: > >    PV Name                /dev/dsk/c8d0s2
: > > VG Name                /dev/vg04
: > >    PV Name                /dev/dsk/c9d0s2
: > >
: > > I need to extract the PV field(s) between the VG Name field(not including
: > > the VG Name field) as there could be more than one PV Name field per volume
: > > group.
: >
: > Are the PV fields on a line by themselves?
: >     grep "^ *PV" infile
: >
: > \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

: >      Consulting                    a world where Ken Thompson is a
: >      Modeling                      relative unknown and Bill Gates is
: >      Training                      a famous billionaire.
: > //////////////////////////////////////////////////////////////////////
: I forgot to mention one other detail, I have to associate the PV fields
: with the VG field above it.

Hi Anthony,

Here's an awk 1-liner for this job:

# cat junk3

VG Name                /dev/vg03
    PV Name                /dev/dsk/c0d0s2
VG Name                /dev/vg01
   PV Name                /dev/dsk/c1d0s2
VG Name                /dev/vg00
   PV Name                /dev/dsk/c2d0s2
VG Name                /dev/vg02
   PV Name                /dev/dsk/c3d0s2
VG Name                /dev/vg07
   PV Name                /dev/dsk/c6d0s2
VG Name                /dev/vg05
   PV Name                /dev/dsk/c7d0s2
VG Name                /dev/vg06
   PV Name                /dev/dsk/c8d0s2
VG Name                /dev/vg04
   PV Name                /dev/dsk/c9d0s2
#
# awk '{if ($1 == "VG"){ printf("%s ", $3) } else { printf("%s\n", $3)}}' junk3

/dev/vg03 /dev/dsk/c0d0s2
/dev/vg01 /dev/dsk/c1d0s2
/dev/vg00 /dev/dsk/c2d0s2
/dev/vg02 /dev/dsk/c3d0s2
/dev/vg07 /dev/dsk/c6d0s2
/dev/vg05 /dev/dsk/c7d0s2
/dev/vg06 /dev/dsk/c8d0s2
/dev/vg04 /dev/dsk/c9d0s2
#

--Joe McCaughan

BTW - You can do vgdisplay -v on individual VGs under HPUX.
eg. vgdisplay -v /dev/vg07 <cr>

 
 
 

1. How to extract second field in ps command output?

Hi,
How can I extract the second field in the ps command output? (the
process id #)
f.e.
ps -ef | grep gopher

root  1402     1 80   Jun 15 ?        0:43
/usr/local/etc/gopherd/gopherd -u
 nobody -l /var/log/gopher

Can I somehow do it with sed or awk or some shell?  Thanks in advance

------------------------------------------------------------------

Albert Einstein College of Medicine   fax:           (718)430-2488
RIT, Bronx, NY.   http://micro6.trincoll.edu, tel:   (718)430-4211
------------------------------------------------------------------

2. Integrated Ethernet Adapter - AUI or BNC selection?

3. Help - sending with mailx to bcc field instead of to: field

4. SDS: Resync of / and /var after rebooting

5. select field n to last? select last field?

6. Positions available

7. Using awk or cut to print every field after the 11th field

8. mpg123 not playing some mp3s

9. Extract fields from records with complicated structure

10. awk - extracting field between "'"

11. Newbie - extracting fields in ksh

12. Extracting date fields using sed and awk

13. sed: extracting single field from each line of a CSV file