bash - Read in and parse textfile -


i need parse file (txt) , display 10 lines of queries number of bytes. (sort) have file log.txt:

164.94.76.83.cust.bluewin.ch - - [17/oct/2006:07:56:45 -0700] "get /example/serif.css http/1.1" 200 4824 "http://www.example.org/example/when/200x/2003/07/25/notgaming" "mozilla/5.0 (windows; u; windows nt 5.1; de; rv:1.8.0.7) gecko/20060909 firefox/1.5.0.7" 164.94.76.83.cust.bluewin.ch - - [03/oct/2006:07:56:45 -0700] "get /example/example.js http/1.1" 200 6685 "http://www.example.org/example/when/200x/2003/07/25/notgaming" "mozilla/5.0 (windows; u; windows nt 5.1; de; rv:1.8.0.7) gecko/20060909 firefox/1.5.0.7" 164.94.76.83.cust.bluewin.ch - - [06/oct/2006:07:56:46 -0700] "get /example/when/200x/2003/07/25/nuke.png http/1.1" 200 19757 "http://www.example.org/example/when/200x/2003/07/25/notgaming" "mozilla/5.0 (windows; u; windows nt 5.1; de; rv:1.8.0.7) gecko/20060909 firefox/1.5.0.7" 164.94.76.83.cust.bluewin.ch - - [15/oct/2006:07:56:46 -0700] "get /example/when/200x/2003/07/25/diablo.png http/1.1" 200 12597 "http://www.example.org/example/when/200x/2003/07/25/notgaming" "mozilla/5.0 (windows; u; windows nt 5.1; de; rv:1.8.0.7) gecko/20060909 firefox/1.5.0.7" 164.94.76.83.cust.bluewin.ch - - [19/oct/2006:07:56:46 -0700] "get /example/when/200x/2003/07/25/-big/nuke.jpg http/1.1" 403 322 " 

output must (with count in % , links - , sort desc):

1. http://www.example.org/example/when/200x/2006/09/25/ - 3100 - 74%                                                     2. http://www.example.org/example/ - 1000 - 24%                 3. http://www.example.org/example/genx/docs/guide.html - 91 - 2%     

that is, necessary highlight line maximum number of bytes in request sort , indicate amount of interest.

since insist on shell-only approach, closest solution ask seems this:

sort -t ' ' -k 10 -r -n log.txt | head -n 10 | awk '{print $1 $7, $10}' 

you can (much) better either setting more useful logformat when logging requests, or allowing perl or python parser when processing logs.


Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -