linux三剑客实战-作业贴

url_summary () 
{ 
    less nginx.log | 
         awk '{print $7}' | 
         sed \
                -e 's#?.*##'   \
                -e '/topics.*replies.*/s#\/[0-9]*\/#\/id\/#g'    \
                -e '/\/photo\//s#\/[0-9a-z-]*\.#\/id\.#'    \
                -e '/uploads\/user\/avatar/s#\/[0-9].*#\/id#'    \
                -e '/\/topics/s#\/[0-9][0-9]*[/]*#\/id\/#' | 
          sort | uniq -c | sort -nr
}

个人认为:
[]里面的内容可以不用转译,因为[]就是一个class符,在[]里面的元字符表示的就是其本身的含义(除了^ 在中括号里表示非,\转译符本身也需要转译即写成[\\],其他的元字符./*?等在中括号里表示的都是它们本身)
所以[0-9a-z\-]可以写成[0-9a-z-],[\/]也可以简写成[/]

url_summary () 
{ 
    awk '{print $7}' nginx.log | sed -e 's/\/topics\/[0-9]\+/\/topics\/id/g' -e 's/\/replies\/[0-9]\+/\/replies\/id/g' -e 's/?.*//g' -e 's/!.*//g' -e 's/\/[0-9a-z-]*\./\/id\./g' | sort | uniq -c | sort -rn | head -10
}

‘’‘bash
url_summary()
{
awk’{print$7}’ nginx.log|
sed
-e ‘s#?.##’
-e ‘/topics.rreplies./s#/[0-9]/#/id/#g
-e '//photo//s#/[a-z0-9-]
.#/id.#’
-e ‘/uploads/user/avatar/s#/[0-9].#/id#’
-e '//topics/s#/[0-9][0-9]
[v]*#/id/#’
sort |uniq -c | sort -nr | head -10
}