- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: first word of second field needed within an aw...
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
тАО09-04-2008 01:25 PM
тАО09-04-2008 01:25 PM
awk '{FS=":";print $1, $2, $3, $6, $8, $9}' > /tmp/inq_et_emc
But the command now outputs slightly different output than it used to. Here is some sample output of the EMC command:
/dev/rdsk/c2t2d0 :HP 73.4G:ST373207LC :HPC3 :3KT5H8PQ :71687369
/dev/rdsk/c2t4d0 :HP 73.4G:ST373207LC :HPC3 :3KT67CDH :71687369
/dev/rdsk/c2t6d0 :HP 73.4G:ST373307LC :HPC8 :3HZ7N6DM :71687369
/dev/rdsk/c5t0d0 :HP :DG072A3515 :HPD1 :BSA1P7A0 :71687369
/dev/rdsk/c5t0d0s1 :HP :DG072A3515 :HPD1 :BSA1P7A0 :512000
/dev/rdsk/c5t0d0s2 :HP :DG072A3515 :HPD1 :BSA1P7A0 :70765569
/dev/rdsk/c5t0d0s3 :HP :DG072A3515 :HPD1 :BSA1P7A0 :409600
/dev/rdsk/c10t0d0 :EMC :SYMMETRIX :5771 :279C8000 :14284801
/dev/rdsk/c10t0d1 :EMC :SYMMETRIX :5771 :279C9000 :14284801
/dev/rdsk/c10t0d2 :EMC :SYMMETRIX :5771 :279CA000 :14284801
/dev/rdsk/c10t0d3 :EMC :SYMMETRIX :5771 :279CB000 :14284801
/dev/rdsk/c10t0d4 :EMC :SYMMETRIX :5771 :279CC000 :14284801
So where I print field $2 to my output file (/tmp/inq_et_emc) I now get "HP 73.4G" whereas I used to only get "HP". This causes me trouble downstream when I read in the output file. (And I would like to avoid adding a field seperator to the new output file).
So what I really want is to only get the first word of field $2, in this case "HP". Is there a variation of substr that would work? I don't want to hardcode a start and end position. Or is there some other sub-command of awk I should be using?
TIA,
Scott
Solved! Go to Solution.
- Tags:
- awk
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-04-2008 01:39 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-04-2008 02:04 PM
тАО09-04-2008 02:04 PM
Re: first word of second field needed within an awk print command
Perhaps you need to split on both space and colon?
awk -F'[ :]' '...'
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-04-2008 02:10 PM
тАО09-04-2008 02:10 PM
Re: first word of second field needed within an awk print command
Denis was right - if you don't specify the separator, the default one (space) was used.
In your case:
/dev/rdsk/c2t2d0 :HP 73.4G ...
1st is /dev/rdsk/c2t2d0
2nd is :HP
3rd is 73.4G
You should specify another separator (-F ":") or better post full output to take a look.
regards,
ivan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-05-2008 05:27 AM
тАО09-05-2008 05:27 AM
Re: first word of second field needed within an awk print command
inq -nodots -system | grep rdsk | grep -v -e ROM -e DVD | sort -k 1 | awk '{FS=":";print $1, $2, $3, $5, $6}' > /tmp/inq
Here is the raw output of the EMC command:
/dev/rdsk/c10t11d1 :EMC :SYMMETRIX :5771 :27A21000 :14284801
/dev/rdsk/c10t11d2 :EMC :SYMMETRIX :5771 :27A22000 :14284801
/dev/rdsk/c10t11d3 :EMC :SYMMETRIX :5771 :27A23000 :14284801
/dev/rdsk/c2t4d0 :HP 73.4G:ST373207LC :HPC3 :3KT67CDH :71687369
/dev/rdsk/c2t6d0 :HP 73.4G:ST373307LC :HPC8 :3HZ7N6DM :71687369
/dev/rdsk/c5t0d0 :HP :DG072A3515 :HPD1 :BSA1P7A0 :71687369
/dev/rdsk/c5t0d0s1 :HP :DG072A3515 :HPD1 :BSA1P7A0 :512000
/dev/rdsk/c5t0d0s2 :HP :DG072A3515 :HPD1 :BSA1P7A0 :70765569
When I do the print $2 on this field ":HP 73.4G:" I need only the "HP" output. Otherwise my next script that reads in this output gets confused.
I still need to try the suggestion I've rec'd so far; that may be the answer.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-05-2008 05:37 AM
тАО09-05-2008 05:37 AM
Re: first word of second field needed within an awk print command
inq -nodots -system | grep rdsk | grep -v -e ROM -e DVD | sort -k 1|grep HP
/dev/rdsk/c2t0d0 :HP 73.4G:ST373307LC :HPC8 :3HZ7L6C1 :71687369
/dev/rdsk/c2t0d0s1 :HP 73.4G:ST373307LC :HPC8 :3HZ7L6C1 :512000
/dev/rdsk/c2t0d0s2 :HP 73.4G:ST373307LC :HPC8 :3HZ7L6C1 :70765737
/dev/rdsk/c2t0d0s3 :HP 73.4G:ST373307LC :HPC8 :3HZ7L6C1 :409600
/dev/rdsk/c2t2d0 :HP 73.4G:ST373207LC :HPC3 :3KT5H8PQ :71687369
/dev/rdsk/c2t4d0 :HP 73.4G:ST373207LC :HPC3 :3KT67CDH :71687369
/dev/rdsk/c2t6d0 :HP 73.4G:ST373307LC :HPC8 :3HZ7N6DM :71687369
/dev/rdsk/c5t0d0 :HP :DG072A3515 :HPD1 :BSA1P7A0 :71687369
/dev/rdsk/c5t0d0s1 :HP :DG072A3515 :HPD1 :BSA1P7A0 :512000
/dev/rdsk/c5t0d0s2 :HP :DG072A3515 :HPD1 :BSA1P7A0 :70765569
/dev/rdsk/c5t0d0s3 :HP :DG072A3515 :HPD1 :BSA1P7A0 :409600
/dev/rdsk/c5t1d0 :HP :DG072A3515 :HPD1 :BSA1P7A0 :71687369
/dev/rdsk/c5t2d0 :HP :DG072A3515 :HPD1 :BSA1P7A0 :71687369
/dev/rdsk/c5t3d0 :HP :DG072A3515 :HPD1 :BSA1P7A0 :71687369
inq -nodots -system | grep rdsk | grep -v -e ROM -e DVD | sort -k 1|grep HP| awk '{FS=":";split($2,a," ");print $1, a[1], $3, $5, $6}'
/dev/rdsk/c2t0d0 HP ST373307LC 3HZ7L6C1 71687369
/dev/rdsk/c2t0d0s1 HP ST373307LC 3HZ7L6C1 512000
/dev/rdsk/c2t0d0s2 HP ST373307LC 3HZ7L6C1 70765737
/dev/rdsk/c2t0d0s3 HP ST373307LC 3HZ7L6C1 409600
/dev/rdsk/c2t2d0 HP ST373207LC 3KT5H8PQ 71687369
/dev/rdsk/c2t4d0 HP ST373207LC 3KT67CDH 71687369
/dev/rdsk/c2t6d0 HP ST373307LC 3HZ7N6DM 71687369
/dev/rdsk/c5t0d0 HP DG072A3515 BSA1P7A0 71687369
/dev/rdsk/c5t0d0s1 HP DG072A3515 BSA1P7A0 512000
/dev/rdsk/c5t0d0s2 HP DG072A3515 BSA1P7A0 70765569
/dev/rdsk/c5t0d0s3 HP DG072A3515 BSA1P7A0 409600
/dev/rdsk/c5t1d0 HP DG072A3515 BSA1P7A0 71687369
/dev/rdsk/c5t2d0 HP DG072A3515 BSA1P7A0 71687369
/dev/rdsk/c5t3d0 HP DG072A3515 BSA1P7A0 71687369
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-05-2008 05:43 AM
тАО09-05-2008 05:43 AM
Re: first word of second field needed within an awk print command
My answer is the same as originally: you can use 'split' with a different field separator to achieve your goal:
# ... | awk '{FS=":";split($2,a," ");print $1,a[1],$3,$5,$6}' > tmp/inq_et_emc
Regards!
...JRF...