UNIX Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsOperating SystemsUNIX Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old September 12th, 2006, 08:42 AM
achieve achieve is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Posts: 127 achieve User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 18 h 48 m 53 sec
Reputation Power: 5
Need help parsing a string

Hi,
I'm writing a shell script that outputs, among other things, some of the information that is outputted by the mysqladmin status command.

The output of the command looks like this:
Uptime: 816351 Threads: 19 Questions: 80719739 Slow queries: 1419 Opens: 15903523 Flush tables: 1 Open tables: 4948 Queries per second avg: 98.879

I need to output the Queries per second, Open tables, and Threads. I know I can count the words on the line and do a cut, but I'd rather do it in a neater fashion.

Is there an easy way to parse this line so that it ouputs:
Uptime: xxxx
Threads: xxx
etc.

and once I have it in that format, I can parse to get the values I want.

Thanks.

Reply With Quote
  #2  
Old September 13th, 2006, 06:51 PM
lozz lozz is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2006
Posts: 3 lozz User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 34 m 50 sec
Reputation Power: 0
You could try -

Code:
#!/bin/sh

FILE="output.txt"

awk '{ print "Uptime " $2 "\nThreads " $4 "\nQuestions: " $6 }' $FILE

# OR

awk '{ print $1 $2 "\n" $3 $4 "\n" $5 $6 }' $FILE

Reply With Quote
Reply

Viewing: Dev Shed ForumsOperating SystemsUNIX Help > Need help parsing a string


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway
Stay green...Green IT