赞助连接

赞助连接

阅 读 文 章

awk脚本输出顺序问题

[来源:网上转载 (http://bbs.chinaunix.net) | 作者:网友(网络转载) | 时间:2008-06-14 | 浏览:人次 ]

% cat datafile
northwest     NW     Joel Craig       3.0     .98     3      4
western       WE     Sharon Kelly     5.3     .97     5     23
southwest     SW     Chris Foster     2.7     .8      2     18
southern      SO     May Chin         5.1     .95     4     15
southeast     SE     Derek Johnson    4.0     .7      4     17
eastern       EA     Susan Beal       4.4     .84     5     20
northeast     NE     TJ Nichols       5.1     .94     3     13
north         NO     Val Shultz       4.5     .89     5      9
central       CT     Sheri Watson     5.7     .94     5     13



% cat awk.sc6
# Awk and the special for loop
{region[$1]++}  # The index is the first field of each record

END{for(item in region){        
        print region[item], item
     }
}

% awk -f awk.sc6 datafile

1 central
1 northwest
1 western
1 southeast
1 north
1 southern
1 northeast
1 southwest
1 eastern

执行awk脚本后,输出第一排是central,第二个变成northwest,请教大家,从上到下,按什么顺序输出的,还是随机输出的?


这个顺序是awk定的,对使用来说没用,你可以认为这是随机的。


TAG标签 : 问题 顺序 输出 脚本 item awk central northwest region

最新评论 共有0位网友发表了评论

发表评论

评论内容:不能超过250字,需审核,请自觉遵守互联网相关政策法规。
用户名:(注册)
密码:
验证码:
匿名发表
网站地图友情连接交流论坛网站投稿广告服务联系我们留言本站长统计
Some rights reserved: www.chmhome.com, 鄂ICP备07010232号 E-mail:chinakafei@live.com,QQ:552766
中国咖啡技术网(Chmhome):国外编程技术书籍,中文编程手册,经典编程文章,交流技术,技术软件下载,计算机论文,毕业论文.