天天看点

awk的关联数组版本支持

今天写一个awk脚本运行时候出现报错:

<code>awk</code> <code>'BEGIN{</code><code>sum</code> <code>= 0; lintCount=0;arrAll[</code><code>"0"</code><code>]=0;}{</code>

<code>for</code><code>(i=1;i&lt;NF;i++){ </code><code>if</code><code>(match($i,/^uri\[/)&gt;0){ match($i,/\[(.*?)\]/,uri);}};</code><code>if</code><code>(match($i,/^logId\[/)&gt;0){match($i,/\[(.*?)\]/,logId);}</code>

<code>split</code><code>(uri[1],arrURI,</code><code>"?"</code><code>);key=arrURI[0];print arrURI;</code>

<code>}' soundui.log.2017091710</code>

<code>awk</code><code>: cmd. line:4: (FILENAME=soundui.log.2017091810 FNR=94565) fatal: attempt to use array `arrAll' </code><code>in</code> <code>a scalar context</code>

这是想统计uri的个数的,但是说不支持关联数组。经过查看:

<code>$ </code><code>awk</code> <code>--version</code>

<code>GNU Awk 3.1.3</code>

<code>Copyright (C) 1989, 1991-2003 Free Software Foundation.</code>

发现是3.1.3,awk需要到4.1以后支持,所以只能升级了!

本文转自 梦朝思夕 51CTO博客,原文链接:http://blog.51cto.com/qiangmzsx/1966849