"awk" personal use of the method to record

Source: Internet
Author: User
Tags ip number

Awk is broad and profound, and I have not been deeply studied in the work except for simple usage.

Another, attach several blog articles, follow up may update this list:

    1. Linux awk Command Detailed http://blog.chinaunix.net/uid-25120309-id-3801250.html

    2. Http://www.cnblogs.com/ggjucheng/archive/2013/01/13/2858470.html


"AWK" Removes the space:awk  ' { result=gensub (/ /, "", 1);p rint result } ' print a section of content:awk  ' {print  $7} '  access.log statistics IP number:awk  ' {cs[$1]+=1} end {for (C IN CS)  print  CS[C], C} '  access.log |sort -nr print the last column:awk  ' {print $8    '   $NF}   '  access.log statistics size:awk  ' {print $10  '     $1  '    '  $7} '  access.log|awk  ' {b+=$1} end {print b/1024/1024  " MB"} ' stats TCP status: Netstat  -n | awk  '/^tcp/ {++state[$NF]} end {for (key in state)   Print key, "\ T", State[key]} ' statistical log in HTTP status code zcat 2013-07-15-0000-2330_cs.ecqun.com.*|awk  ' {print  $9} ' |sort|uniq -c|sort -nr|more statistic log format the last line is the corresponding data of the source station IP zcat 2013-07-15-*|awk  ' $7~/ cs.ecqun.com/{print  $NF} ' |sort|uniq -c|sort -nr| 18-point access to cs.ecqun.com, status code 200 data, print response time and source station address in head statistics log zcat 2013-07-15-18*|grep cs.ecqun.com|awk  ' $9== "{print $ (NF-7), $NF} ' |sort|uniq -c|sort -nr| More statistics delay more than 100ms requests zcat 2013-07-15-18*|grep cs.ecqun.com|awk  ' $9== "0" &&$ (NF-7) >100  {print $ (NF-7)} ' |sort|uniq -c|sort -nr|morenr: The number of records that the entire script is currently reading, which is the line number, starting with 1. As the number of files read, it always accumulates. FNR: Same as NR, but relative to the number of file records currently being read. Each time you start reading a file, it starts at 1 and is equivalent to the line number. After reading a file will clear 0, the new file will start from 1. http://in.sdo.com/?p=1054 Statistics Http code is 502 of the number, IP assumes the following file:cs.502 :  statistics appear 502 times and IP, in the format of "Times    ip "cs.502.ip :  filter IP from cs.502, in the format" IP "cs.502.country :  use Qqwry for IP-to-geo conversion, in the format" ip    Location "The need now is to combine cs.502 and Cs.502.country awk  ' Nr==fnr {a[$2]=$0;next} nr>fnr {print  a[$1]  " " $  cs.502 cs.502.country >cs.502.log calculation http code  The relative total proportion of the overseas is how much test.all  content is:46255 0967 504218 502test.oversea  content is:1171 0408  504205 502awk  ' nr==fnr {a[$2]=$1;next} nr>fnr {printf  '%.2f%  ",  $1/a[$2]*100;print $2} '  test.all test.oversea 2.53% 042.19%  50494.04% 502 calculated percentage:echo 55 4001638 |awk  ' {printf  "%.4f%\n", $1/$2*100} ' Sort:123123421432904920342390492304920394023209402394023940234awk  ' {print $0,substr ($0,length) according to the latter 3 bits ) -2,3} '  x.txt |sort -n -k 2 | awk  ' {print $1} ' sed -r  ' s/(. *) ((.) {3}) /\1|\2/'  test.txt |sort -n -k 2 -t \| |sed  ' s/|//g ' go heavy  awk   '!a[$1]++ '  test.log


"awk" personal use of the method to record

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.