- Community Home
- >
- Servers and Operating Systems
- >
- Operating System - Linux
- >
- System Administration
- >
- Re: Scripting Awk help
-
- Forums
-
- Advancing Life & Work
- Advantage EX
- Alliances
- Around the Storage Block
- HPE Ezmeral: Uncut
- OEM Solutions
- Servers & Systems: The Right Compute
- Tech Insights
- The Cloud Experience Everywhere
- HPE Blog, Austria, Germany & Switzerland
- Blog HPE, France
- HPE Blog, Italy
- HPE Blog, Japan
- HPE Blog, Middle East
- HPE Blog, Russia
- HPE Blog, Saudi Arabia
- HPE Blog, South Africa
- HPE Blog, UK & Ireland
-
Blogs
- Advancing Life & Work
- Advantage EX
- Alliances
- Around the Storage Block
- HPE Blog, Latin America
- HPE Blog, Middle East
- HPE Blog, Saudi Arabia
- HPE Blog, South Africa
- HPE Blog, UK & Ireland
- HPE Ezmeral: Uncut
- OEM Solutions
- Servers & Systems: The Right Compute
- Tech Insights
- The Cloud Experience Everywhere
-
Information
- Community
- Welcome
- Getting Started
- FAQ
- Ranking Overview
- Rules of Participation
- Tips and Tricks
- Resources
- Announcements
- Email us
- Feedback
- Information Libraries
- Integrated Systems
- Networking
- Servers
- Storage
- Other HPE Sites
- Support Center
- Aruba Airheads Community
- Enterprise.nxt
- HPE Dev Community
- Cloud28+ Community
- Marketplace
-
Forums
-
Blogs
-
Information
-
English
- 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
- Email to a Friend
- Report Inappropriate Content
11-14-2013 07:53 AM - last edited on 11-15-2013 01:49 AM by Lisa198503
11-14-2013 07:53 AM - last edited on 11-15-2013 01:49 AM by Lisa198503
Ive posted this in the Linux forum but decided to repost here because I normally get a better response:
I'd like some help with a script
I have a file with the following data
Device Product Device
---------------------- --------------------------- ---------------------
Name Type Vendor ID Rev Ser Num Cap (KB)
---------------------- --------------------------- ---------------------
/dev/sdbc M(2) EMC SYMMETRIX 5876 110265D000 17677440
/dev/sdbd M(3) EMC SYMMETRIX 5876 110265F000 53032320
/dev/sdbe M(2) EMC SYMMETRIX 5876 1102705000 17677440
/dev/sdbf DGC RAID 5 0326 8600001D 62914560
/dev/sdbg DGC RAID 5 0326 8D0000AA 199229440
/dev/sdbh DGC RAID 5 0326 09000028 26214400
/dev/emcpoweraa DGC RAID 5 0326 8600001D 62914560
some lines have 6 fields and other lines have seven fields
I execute the pvs command and I want to search each lun from the EMC output and depending on the number of fields to determine what to print
PV VG Fmt Attr PSize PFree
/dev/emcpowerm emcvg lvm2 a- 67.43G 0
/dev/emcpowero VG1 lvm2 a- 16.86G 11.86G
/dev/emcpowerp bc2eoaipp1vg lvm2 a- 50.57G 8.57G
/dev/sda2 systemvg lvm2 a- 33.59G 0
/dev/sdad emcvg lvm2 a- 67.43G 428.00M
so I have come up with
cat /tmp/pvs |awk 'NR>1 {sub("\/dev\/","",$1);print $1,$2,$5}' |while read PV VG PSZ
do
awk -v search=${PV} '$0 ~ search {if (line != "") print line; line =$NF} {if(NF==6) {line=$1":"$4":"$5":"$NF}} {if(NF==7) {line=$1":"$5":"$6":"$NF}};END{print line}' /tmp/symcli.data)
done
it doesnt quite work because the output is the same
/dev/emcpoweraa:0326:8600001D:62914560
/dev/emcpoweraa:0326:8600001D:62914560
/dev/emcpoweraa:0326:8600001D:62914560
/dev/emcpoweraa:0326:8600001D:62914560
/dev/emcpoweraa:0326:8600001D:62914560
/dev/emcpoweraa:0326:8600001D:62914560
/dev/emcpoweraa:0326:8600001D:62914560
can someone help out with the syntax please :)
thanks
Chris
P.S. This thread has been moved from HP-UX-Languages and Scripting to Linux - sysadmin. -HP Forum Moderator
Solved! Go to Solution.
- Tags:
- awk
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
11-15-2013 12:35 AM
11-15-2013 12:35 AM
Solution>I have a file with the following data
The two files that you have produce no output, after fixing your scripts.
It helps if you format them better (and remove the evil cat):
awk '
NR > 1 {
sub("/dev/","",$1)
print $1, $2, $5
}' /tmp/pvs |
while read PV VG PSZ; do
awk -v search=${PV} '
$0 ~ search {
if (NF==6) {
line=$1 ":" $4 ":" $5 ":" $NF
} else if (NF==7) {
line=$1 ":" $5 ":" $6 ":" $NF
}
print line
exit # stop after first match
}' /tmp/symcli.data
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
11-15-2013 03:05 AM
11-15-2013 03:05 AM
Re: Scripting Awk help
thank you Dennis
that 'cat' command was there to simulate the pvs command but again your help is greatly appreciated :)
cheerrs
Chris
Hewlett Packard Enterprise International
- Communities
- HPE Blogs and Forum
© Copyright 2021 Hewlett Packard Enterprise Development LP