#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2003
    Posts
    147
    Rep Power
    15

    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.
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2006
    Posts
    3
    Rep 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

IMN logo majestic logo threadwatch logo seochat tools logo