Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

流量统计脚本出错 #142

Open
BoringCat opened this issue Feb 28, 2020 · 0 comments
Open

流量统计脚本出错 #142

BoringCat opened this issue Feb 28, 2020 · 0 comments
Labels
unconfirmed Waiting investigation

Comments

@BoringCat
Copy link

高级篇-->流量统计-->流量信息的处理中实例脚本的awk命令出错

  • 详细信息:
    v2ctl输出中存在换行符\r\n,脚本中 gsub(/^"|link"$/, "", $2); 无法匹配到后面的link,导致输出 inbound:api->uplink" 而非 inbound:api->up
    脚本中 else if (match($0, /^>$/) && f) { f = 0; print 0; } 无法匹配 >,在无数据的情况下没有输出0,导致 print_sum() 报错 numfmt: 无效的数字:“”

  • 修正:
    在匹配行末的正则表达式中插入\s?,表示“匹配存在的任意空白字符”,以匹配多种换行符或无换行符的情况

     | awk '{
         if (match($1, /name:/)) {
-            f=1; gsub(/^"|link"$/, "", $2);
+            f=1; gsub(/^"|link"\s?$/, "", $2);
             split($2, p,  ">>>");
             printf "%s:%s->%s\t", p[1],p[2],p[4];
         }
         else if (match($1, /value:/) && f){ f = 0; printf "%.0f\n", $2; }
-        else if (match($0, /^>$/) && f) { f = 0; print 0; }
+        else if (match($0, /^>\s?$/) && f) { f = 0; print "0"; }
     }'
@nicholascw nicholascw added the unconfirmed Waiting investigation label Mar 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
unconfirmed Waiting investigation
Projects
None yet
Development

No branches or pull requests

2 participants