- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Awk - using one field separator, then another?
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
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
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-18-2003 01:47 AM
09-18-2003 01:47 AM
Here's one thats been bugging me for a while. Basically, I want to pull out the current load average from uptime ie :
10:46am up 55 days, 14:06, 159 users, load average: 3.34, 3.28, 3.39
Theory goes, use and FS of ":" and get the 4th field, then use an FS of "," and get the first thus ending up with 3.34. I'm sure there are better ways but I've come across a similar problem before and want to know whether this is possible in awk?
As always, help greatly appreciated.
Cheers,
Tony
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-18-2003 02:07 AM
09-18-2003 02:07 AM
Re: Awk - using one field separator, then another?
expr "`uptime`" : ".*load average: \(.*\)" and pipe the
output into "cut" or "awk" or whatever.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-18-2003 02:28 AM
09-18-2003 02:28 AM
Re: Awk - using one field separator, then another?
1) you can replace "," with spaces either with sed or tr before you pipe results into awk
2) you can use the split function in awk
split(s,a,fs) fs = field separator
Rgds,
Jean-Luc
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-18-2003 02:38 AM
09-18-2003 02:38 AM
Re: Awk - using one field separator, then another?
Thanks!
Tony
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-18-2003 02:45 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-18-2003 03:31 AM
09-18-2003 03:31 AM
Re: Awk - using one field separator, then another?
It looks like you Jean-Luc, and you now have the opportunity to award them. At any rate, another approach could be:
echo $In|cut -d\: -f2|cut -d\, -f[1|2|3]
choose which field [1|2|3] you want....
Not looking for points - just providing an alternative.
Rob
Zero points
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-18-2003 03:34 AM
09-18-2003 03:34 AM
Re: Awk - using one field separator, then another?
make that,
"It looks like you OWE Jean-Luc...."
Rob
Zero points
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-18-2003 03:37 AM
09-18-2003 03:37 AM
Re: Awk - using one field separator, then another?
(sorry!!)...AND *Y O U* will be the one to promote Jean-Luc to *W I Z A R D*
Too compelling to pass up, I'd say!
Rob
Zero points
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-18-2003 03:41 AM
09-18-2003 03:41 AM
Re: Awk - using one field separator, then another?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-18-2003 04:02 AM
09-18-2003 04:02 AM
Re: Awk - using one field separator, then another?
I would like to see a complete example.
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
09-18-2003 05:28 AM
09-18-2003 05:28 AM
Re: Awk - using one field separator, then another?
uptime|awk -F: '{MYVAR=$4;split(MYVAR,mv,",");print mv[1]}'
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-18-2003 05:59 AM
09-18-2003 05:59 AM
Re: Awk - using one field separator, then another?
The -F argument and corresponding FS variable is a full regular expression. So in this case you can just use both "," and ":" as seperators giving:
uptime|awk -F[:,] '{print $7}'
fwiw,
Hein.