- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- print fields suing awk
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
Forums
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
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
тАО04-24-2007 01:34 AM
тАО04-24-2007 01:34 AM
I posted a thread earlier but I think I need to elaborate, I am still learning awk and my syntax is all over the place ie prints unexpected fields etc ....
eg I am running these commands on AIX so I hope that doesnt offend the HPUX guru's here ...
eg:
lsvg rootvg
VOLUME GROUP: rootvg VG IDENTIFIER: 0045278a00004c000000010deef5d831
VG STATE: active PP SIZE: 128 megabyte(s)
VG PERMISSION: read/write TOTAL PPs: 270 (34560 megabytes)
MAX LVs: 256 FREE PPs: 72 (9216 megabytes)
LVs: 11 USED PPs: 198 (25344 megabytes)
OPEN LVs: 10 QUORUM: 1
TOTAL PVs: 2 VG DESCRIPTORS: 3
STALE PVs: 0 STALE PPs: 0
ACTIVE PVs: 2 AUTO ON: no
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
from this output I want to print
TOTAL 270 34560
FREE 72 9216
USED 198 25344
the problem I am having is determining the field and rows to print in awk ....
any help is much appreciated.
Thanks
Chris
Solved! Go to Solution.
- Tags:
- awk
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-24-2007 01:39 AM
тАО04-24-2007 01:39 AM
Re: print fields suing awk
from the lsvg rootvg the actual fields are:
TOTAL PPs: 270 (34560 megabytes)
FREE PPs: 72 (9216 megabytes)
USED PPs: 198 (25344 megabytes)
lsvg rootvg |awk '/PPs:/ && ! /STALE/ {print ????}'
???? is the problem because the USED field is not $4,$6,$7
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-24-2007 01:48 AM
тАО04-24-2007 01:48 AM
Re: print fields suing awk
Here's one way. You can adapt the matching for the FREE and USED portions easily:
# lsvg rootvg|awk '/TOTAL PP/ {split($7,a,/[()]/);print $4,$6,a[2]}'
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-24-2007 01:49 AM
тАО04-24-2007 01:49 AM
Re: print fields suing awk
When you say you had an earlier thread, post a link.
I think this is it.
http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=1121029
I can discern little else from your input, but will give you a little example.
Lets say I have output that looks like this:
Field1 Field2 Field3
To print it.
cat (whatever) | awk '{ print $1 $2 $3}'
To get field two into a variable
F2=$(cat $DATA | awk '{ print $2 }')
Try and take some time to explain the problem and give background.
SEP
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-24-2007 02:01 AM
тАО04-24-2007 02:01 AM
SolutionUsually I call sed to the rescue in such situations (sed & awk get along great).
Try this:
# lsvg rootvg | sed -ne 's/[()]//g' -e 's/.*\(TOTAL PP.*\)/\1/p' -e 's/.*\(FREE PP.*\)/\1/p' -e 's/.*\(USED PP.*\)/\1/p'
After that, the awk becomes way easier ;-)
|awk '{print $1,$3,$4}'
Cheers,
Wout
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-24-2007 02:02 AM
тАО04-24-2007 02:02 AM
Re: print fields suing awk
lsvg rootvg | awk '/PPs:/ && ! /STALE/ {if ($1 == "LVs:") print $3, $5, $6 else print $4, $6, $7}' | sed 's/(//'
The sed is just to get rid of that ( in the third printed field.
Jeff Traigle
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-24-2007 02:11 AM
тАО04-24-2007 02:11 AM
Re: print fields suing awk
Since the "USED" fields are not ordinally in the same place as the "TOTAL" or "FREE" lines, we can do this:
# lsvg rootvg | awk '/TOTAL PP|FREE PP/ {split($7,a,/[()]/);print $4,$6,a[2]};/USED PP/ {split($6,a,/[()]/);print $3,$5,a[2]}'
TOTAL 270 34560
FREE 72 9216
USED 198 25344
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-24-2007 02:17 AM
тАО04-24-2007 02:17 AM
Re: print fields suing awk
my sad effort would be along the lines of:
awk '{print $(NF-4),$(NF-3),$(NF-2),$(NF-1)}'
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-24-2007 02:58 AM
тАО04-24-2007 02:58 AM
Re: print fields suing awk
Brief explaination ...
we upload stats to a central DB which then give us peformance and capacity data, this data will tell us when we will need to add more disk to the system.
The capacity manager wants the output to appear as below without the headers because he will set this at his end:
volumegroup,PP SIZE,FREE PPs,TOTAL PPs
rootvg,128,72,270
Thanks again
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-24-2007 03:49 AM
тАО04-24-2007 03:49 AM
Re: print fields suing awk
# lsvg rootvg | awk 'NR==1 {VG=$3};/PP SIZE/ {SZ=$6};/FREE PP/ {FREE=$6};/TOTAL PP/ {TOT=$6};END{OFS=",";print VG,SZ,FREE,TOT}'
rootvg,128,72,270
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-24-2007 04:34 AM
тАО04-24-2007 04:34 AM
Re: print fields suing awk
# awk '/VOLUME GROUP/{if(a) printf("%s ",a);a=$3}
/PP SIZE/{if(b) printf("%s ",b);b=$6}
/TOTAL PPs/{if(c) printf("%s ",c);c=$6}
/FREE PPs/{if(d) printf("%s\n",d);d=$6}
END{print a,b,c,d}' inp
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-24-2007 11:44 PM
тАО04-24-2007 11:44 PM
Re: print fields suing awk
both examples are good however sandman I will toruble shoot your example and get back to you as no output is displayed.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-25-2007 03:02 PM - edited тАО10-02-2011 09:45 PM
тАО04-25-2007 03:02 PM - edited тАО10-02-2011 09:45 PM
Re: print fields using awk
>I will trouble shoot your example and get back to you as no output is displayed.
Hmm, I get output if you assume that you made two copies of your initial lsvg output. Sandman does have the free after the total.
Here my suggested changes that prints complete lines:
awk '
BEGIN { VG=""; SZ=""; FREE=""; TOT="" }
/VOLUME GROUP/ {
if (VG) print VG "," SZ "," FREE "," TOT
VG=$3
}
/PP SIZE/ {SZ=$6}
/TOTAL PPs/ {TOT=$6}
/FREE PPs/ {FREE=$6}
END { print VG "," SZ "," FREE "," TOT }'
The BEGIN isn't strictly needed.
You could use OFS like JRF did in his print.