2

We have logging our disk array with iostat, and now have a 2 mb text file. Is it possible to read the file contents, and sort all occurrences in some way, with php or bash?

We also have shell access, so if you're a commande guru, that's also a possibility.

We want to read and sort the following information in a text file, ascending, by some of the following r/s, w/s, kr/s, kw/s, qlen, svc_t or %b values.

Possible, or too difficult?

                        extended device statistics
device     r/s   w/s    kr/s    kw/s qlen svc_t  %b
da0       11.5  14.0   701.8   530.1    0   7.3  11
                        extended device statistics
device     r/s   w/s    kr/s    kw/s qlen svc_t  %b
da0        0.0   0.0     0.0     0.0    1   0.0   0
                        extended device statistics
device     r/s   w/s    kr/s    kw/s qlen svc_t  %b
da0        0.0  10.5     0.0   350.8    0 139.2 145
1
  • If text file grows, sort will be too expensive and slow. I think you should use SQLITE or MySql.If you want to use txt log files, I don't know about bash, but python can help a lot. you need maps. Commented Dec 5, 2015 at 11:40

1 Answer 1

3

Try this to sort column 3 ("w/s"):

(echo 'device r/s w/s kr/s kw/s qlen svc_t %b'; grep '[0-9]' file | sed 's/ \+/ /g' | sort -n -k 3,3 ) | column -t

or this to sort column 7 ("svc_t"):

(echo 'device r/s w/s kr/s kw/s qlen svc_t %b'; grep '[0-9]' file | sed 's/ \+/ /g' | sort -n -k 7,7 ) | column -t

Output with -k 7,7:

device  r/s   w/s   kr/s   kw/s   qlen  svc_t  %b
da0     0.0   0.0   0.0    0.0    1     0.0    0
da0     11.5  14.0  701.8  530.1  0     7.3    11
da0     0.0   10.5  0.0    350.8  0     139.2  145

With awk or printf it's possible to align the colums right.

Sign up to request clarification or add additional context in comments.

1 Comment

Absolutely amazing, how is this even possible. A huge tanks @Cyrus!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.