Shell scripts can quickly obtain a parameter in the access log.

Source: Internet
Author: User

For example, if we count Sid, the access log is as follows:

203.142.196.181--[07/Jan/2009: 06: 02: 58 + 0900] "Get/AD/queryphp. jsp? V = 1.5 & Ct = i02 & TOS = A & Key = % 3f % 3f % 3f & SID = 100575311 & ENC = sjis HTTP/1.0 "200 944"-"" {KDDI-SN3B up. browser/6.2.0.13.1.5 (GUI) MMP/2.0} "113185 1177

You can only use awk to complete the process. First, split by "SID =", take the second column, and then split by "&". Then, take the first column and OK.

Awk-F "SID =" '{print $2}' test | awk-F "&" '{print $1 }'

Another method is to use echo to remove the head and tail.

A = $ (echo string); # source string

B = $ (echo "$ {A # * SID =}") # extract the data after the SID.

Echo "$ {B % & *}" # tail and remove all & S

So powerful !!!!!

Related Article

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.