- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: awk on vgdisplay output
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-10-2004 11:27 PM
тАО08-10-2004 11:27 PM
---
VG Name /dev/vgbackup
Max PV 16
Cur PV 2
Max PE per PV 59466
PE Size (Mbytes) 16
VG Name /dev/vgtbl10
Max PV 16
Cur PV 16
Max PE per PV 1023
PE Size (Mbytes) 4
VG Name /dev/vgredo
Max PV 16
Cur PV 10
Max PE per PV 1016
PE Size (Mbytes) 4
VG Name /dev/rdvgcp
Max PV 16
Cur PV 3
Max PE per PV 13071
PE Size (Mbytes) 16
----------
I need the Record Separator as VG Name. That means each record is starting from VG Name up to PE Size (5 lines).
VG Name /dev/vgbackup
Max PV 16
Cur PV 2
Max PE per PV 59466
PE Size (Mbytes) 16
I need to use awk which should consider the first five lines as a record then print it on a single line separated by comma (,)
So the output should be something like this:
VG Name,/dev/vgbackup,Max PV,16,Cur PV,2,Max PE per PV,59466,PE Size (Mbytes),16
Thanks
Rasheed.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-10-2004 11:45 PM
тАО08-10-2004 11:45 PM
Re: awk on vgdisplay output
Since 5 lines each time
let x=0
outline=""
cat $1|while read line
do
let x=$x+1
if [ "$x" -eq 1 ]
then
outline=$line
else
outline=$outline","$line
fi
if [ "$x" -eq "5" ]
then
echo "$outline"
let x=0
fi
done
File is parameter
Steve Steel
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-10-2004 11:47 PM
тАО08-10-2004 11:47 PM
Re: awk on vgdisplay output
for i in `cat data`
do
if [ $i = "VG" ]
then
echo
fi
echo "$i \c"
done
echo
Note: This script does not put , (comma).
sks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-10-2004 11:58 PM
тАО08-10-2004 11:58 PM
Solution# awk '{ if ( NR %5 == 4 ) printf $1" "$2" "$3" "$4","$5","
if ( NR %5 == 0 ) printf $1" "$2" "$3","$4"\n"
if ( NR %5 == 1 || NR %5 == 2 || NR %5 == 3 )
printf $1" "$2","$3","
}' filename
Results
--------
VG Name,/dev/vgbackup,Max PV,16,Cur PV,2,Max PE per PV,59466,PE Size (Mbytes),16
VG Name,/dev/vgtbl10,Max PV,16,Cur PV,16,Max PE per PV,1023,PE Size (Mbytes),4
VG Name,/dev/vgredo,Max PV,16,Cur PV,10,Max PE per PV,1016,PE Size (Mbytes),4
VG Name,/dev/rdvgcp,Max PV,16,Cur PV,3,Max PE per PV,13071,PE Size (Mbytes),16
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-11-2004 01:46 AM
тАО08-11-2004 01:46 AM
Re: awk on vgdisplay output
perl -ne 'chomp; $line=/^VG Name/ ? $_ : $line.",".$_; print $line,"\n" if /^PE Size/' vgoutputfile
HTH
-- Rod Hills
- Tags:
- Perl
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-12-2004 01:07 AM
тАО08-12-2004 01:07 AM
Re: awk on vgdisplay output
#/home/scripts/volbuild
# more volbuild
cd /pei/peitools/bin
echo 'This script will build and create database space,
Please not you should know about how much disk space is required
and available.. Below is a listing of free space in existing
Volume Groups'
echo "Enter Enter District ID:"
read district
for vg in `grep "LV Name" vg.txt |awk '{print $3}' |grep dbs |grep -v vg00 |grep -v log |grep -v root |grep -v tmp |grep
$district`
do
vgrp=`lvdisplay $vg |grep "VG Name"|awk '{print $3}'`
echo -------- Logical Volume `lvdisplay $vg |grep "LV Name"` --------
lvdisplay $vg |grep "LV Name"
echo $vgrp
lvdisplay $vg |grep "LV Size"
vgdisplay $vgrp |grep Free
export dbspace=`lvdisplay $vg |grep "LV Name" |awk '{print substr($3, 11, 6)}'`
export vgrp=`lvdisplay $vg |grep "VG Name"|awk '{print $3}'`
export nvol=`lvdisplay $vg |grep "LV Name" |awk '{print substr($3, 17, 1)}'`
if [ -z "$nvol" ]
then export nvol=0
fi
export i=`expr $nvol + 1`
done
echo "Enter Size of Volume"
read size
export size
echo lvcreate -L $size -n $dbspace$i $vgrp
cd $vgrp
echo chown informix:informix r$dbspace$i
echo chmod 660 r$dbspace$i
export fname=r$dbspace$i
cd /dev/online
#
ls $fname
echo ln -s $vgrp/$fname $dbspace$i
echo onspaces -a $dbspace$i -p /dev/online/$fname -o 0 -s "$size"000
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-12-2004 03:22 AM
тАО08-12-2004 03:22 AM
Re: awk on vgdisplay output
Hmmm, my vgdisplay (11.23) shows more lines. For example:
VG Name /dev/vg00
VG Write Access read/write
VG Status available
Max LV 255
Cur LV 8
Open LV 8
Max PV 16
Cur PV 1
Act PV 1
Max PE per PV 4328
So I would recommend you protect against that and select 'just what you need'.
My perl 'one-liner' woudl be explicit about matches:
vgdisplay -v | perl -ne '
if (/^(VG Name|Max PV|Max PE per PV)\s+(\S+)/)
{ $x .= "$1,$2," }
if (/(PE Size \(Mbytes\))\s+(\d+)/){print "$x$1,$2\n"; $x=""}'
This says:
If the string starts with one of 4 expliciti strings, then glue that string , plus a comma, plus the next series of non-whitespace, plus a comma to a workstring 'x'.
Look explicitly for the last match and print temp + last.
Result for me:
VG Name,/dev/vg00,Max PV,16,Max PE per PV,4328,PE Size (Mbytes),16
VG Name,/dev/vg_oltp,Max PV,16,Max PE per PV,65535,PE Size (Mbytes),32
:
hth,
Hein.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-12-2004 04:10 AM
тАО08-12-2004 04:10 AM
Re: awk on vgdisplay output
Just for yucks...
It bothered me I could not come up with a nice generic way to catch the words before the value. So without hardcoding files numbers/names.
first potential solution... just take enough interesting bytes for the name, then trim some.
awk '{n=substr($0,1,22);gsub(/ +/," ",n);x=x n "," $NF ","}/^PE S/{sub(/.$/,"",x); print x;x=""}'
Second potential solution... first collapse all multiple spaces to single space. The use the position of the last field as the end of the name + 2:
awk '{gsub(/ +/," ");x=x substr($0,1,index($0,$NF)-2) "," $NF ","}/^PE S/{sub(/.$/,"",x); print x;x=""}'
Ok.... back to real work.
Hein.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-12-2004 04:49 AM
тАО08-12-2004 04:49 AM
Re: awk on vgdisplay output
You want a ,(comma) as seperator between the field label and the data.
IE:
fieldname, data, fieldname, data, etc
This worked on my system:
vgdisplay | awk '
( $0 ~ /VG Name/ ) {
for (i = 1; i <= 4; i++)
{
while (gsub(/ /," "));
fields=split($0,data," ")
for (f = 1; f < fields; f++)
printf("%s ",data[f])
printf(",%s,",data[fields])
getline
}
while (gsub(/ /," "));
fields=split($0,data," ")
for (f = 1; f < fields; f++)
printf("%s ",data[f])
printf(",%s\n",data[fields])
}
'
vgdisplay | awk ' #imput stream to awk
( $0 ~ /VG Name/ ) { # find first record
for (i = 1; i <= 4; i++) #next four lines
{
while (gsub(/ /," ")); #reduce white space
fields=split($0,data," ") #split into fields
#print all the line fields except last
#this is field name
for (f = 1; f < fields; f++)
printf("%s ",data[f])
#print a comma and then the data field
printf(",%s,",data[fields])
getline
}
#Do the last line as above ending in a
# linefeed
while (gsub(/ /," "));
fields=split($0,data," ")
for (f = 1; f < fields; f++)
printf("%s ",data[f])
printf(",%s\n",data[fields])
}
'