Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

awk block 1

Status
Not open for further replies.

Mag0007

MIS
Feb 15, 2005
829
US
If I have something like this

VOLUME GROUP: rootvg VG IDENTIFIER:
000bc6fd00004c00000000fda469279d
VG STATE: active PP SIZE: 16 megabyte(s)
VG PERMISSION: read/write TOTAL PPs: 542 (8672 megabytes)
MAX Lvs: 256 FREE PPs: 431 (6896 Megabytes)
LVs: 9 USED PPs: 111 (1776 megabytes)
OPEN LVs: 8 QUORUM: 2
TOTAL PVs: 1 VG DESCRIPTORS: 2
STALE PVs: 0 STALE PPs: 0
ACTIVE PVs: 1 AUTO ON: yes
MAX PPs per VG: 32512
MAX PPs per PV: 1016 MAX PVs: 32
LTG size (Dynamic): 256 kilobyte(s) AUTO SYNC: no
HOT SPARE: no BB POLICY: relocatable

Is it possible to get values
 
sorry premature post!

Is it possible to get values of VG IDENTIFIER, FREE PPs, etc..etc.. using awk?
 
yes, it is!

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
I can get it via line by line basis, but I would like this whole block to get values such as $1, $2, etc..etc..
 
Hi

No, I think you can not get them in variables, only in array elements. Assuming that the VG IDENTIFIER's value goes in a new line accidentally when copy&pasting it :
Code:
{
  match($0,/(.*)   ([[:upper:]].*)/,a)
  for (i=1;i in a;i++) {
    split(a[i],b,/:/)
    v[b[1]]=gensub(/^ */,"","",b[2])
  }
}

END {
  print v["VG IDENTIFIER"]
  print v["FREE PPs"]
}
Unless you tell more about that file.

Feherke.
 
WOW! this is harder then I though. Are you using perl feherke?

OKay forget my example. What if I have this

apple orange
mango grape

Can I get apple, orange, mango, grape as $1 $2 $3 $4, respectivly?
 
does this kind of thing help?:-

Code:
[b]#!/usr/bin/perl[/b]

undef $/;
$_ = <DATA>;
$/ = "\n";

m/VG IDENTIFIER:[ \n]+([a-z0-9]+).*FREE PPs: (\d+) .*USED PPs: (\d+) /s;

print "VG=$1\nFREE PPs=$2\nUSED PPs=$3";

[blue]__DATA__
VOLUME GROUP:            rootvg             VG IDENTIFIER: 
                                            000bc6fd00004c00000000fda469279d
VG STATE:               active             PP SIZE: 16 megabyte(s)
VG PERMISSION:             read/write     TOTAL PPs: 542 (8672 megabytes)
MAX Lvs:         256         FREE PPs: 431 (6896 Megabytes)
LVs:             9         USED PPs: 111 (1776 megabytes)
OPEN LVs:         8         QUORUM: 2
TOTAL PVs:         1         VG DESCRIPTORS: 2
STALE PVs:         0         STALE PPs: 0
ACTIVE PVs:         1         AUTO ON: yes
MAX PPs per VG:     32512
MAX PPs per PV:     1016         MAX PVs: 32
LTG size (Dynamic):     256 kilobyte(s) AUTO SYNC: no
HOT SPARE:         no         BB POLICY: relocatable[/blue]


Kind Regards
Duncan
 
the above sets $1, $2 & $3 respectively:-

Code:
VG=000bc6fd00004c00000000fda469279d
FREE PPs=431
USED PPs=111


Kind Regards
Duncan
 
given data file mag.txt:
Code:
apple orange
mango grape

dog cat
zebra horse

and mag.awk:
Code:
BEGIN {
  RS=""
}
{
  printf("\nblock-> [%s]\n", $0)

  print "\nnow by fields"
  for(i=1; i <= NF; i++)
    printf("field->[%d] value->[%s]\n", i, $i)
}

nawk -f mag.awk mag.txt
produces:
Code:
block-> [apple orange
mango grape]

now by fields
field->[1] value->[apple]
field->[2] value->[orange]
field->[3] value->[mango]
field->[4] value->[grape]

block-> [dog cat
zebra horse]

now by fields
field->[1] value->[dog]
field->[2] value->[cat]
field->[3] value->[zebra]
field->[4] value->[horse]

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
vgersh99:
AMAZING! Thats exactly what I was looking for!!!!!!

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top