免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2625 | 回复: 1
打印 上一主题 下一主题

[文本处理] PROCINFO["sorted_in"]="@ind_str_asc"什么意思? [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2014-10-03 12:32 |只看该作者 |倒序浏览
awk '
BEGIN {
      PROCINFO["sorted_in"]="@ind_str_asc";
   }

       {
       do sth..
   }
'
问题: PROCINFO["sorted_in"]="@ind_str_asc";什么意思?PROCINFO["sorted_in"]="@ind_num_asc";什么意思?

论坛徽章:
145
技术图书徽章
日期:2013-10-01 15:32:13戌狗
日期:2013-10-25 13:31:35金牛座
日期:2013-11-04 16:22:07子鼠
日期:2013-11-18 18:48:57白羊座
日期:2013-11-29 10:09:11狮子座
日期:2013-12-12 09:57:42白羊座
日期:2013-12-24 16:24:46辰龙
日期:2014-01-08 15:26:12技术图书徽章
日期:2014-01-17 13:24:40巳蛇
日期:2014-02-18 14:32:59未羊
日期:2014-02-20 14:12:13白羊座
日期:2014-02-26 12:06:59
2 [报告]
发表于 2014-10-03 13:03 |只看该作者
本帖最后由 jason680 于 2014-10-03 13:09 编辑

回复 1# wy200747055

http://www.gnu.org/software/gawk ... ontrolling-Scanning

8.1.5 Scanning All Elements of an Array
...

8.1.6 Using Predefined Array Scanning Orders

By default, when a for loop traverses an array, the order is undefined, meaning that the awk implementation determines the order in which the array is traversed. This order is usually based on the internal implementation of arrays and will vary from one version of awk to the next.

Often, though, you may wish to do something simple, such as “traverse the array by comparing the indices in ascending order,” or “traverse the array by comparing the values in descending order.” gawk provides two mechanisms which give you this control.

    Set PROCINFO["sorted_in"] to one of a set of predefined values. We describe this now.
    Set PROCINFO["sorted_in"] to the name of a user-defined function to use for comparison of array elements. This advanced feature is described later, in Array Sorting.


The following special values for PROCINFO["sorted_in"] are available:

"@unsorted"
    Array elements are processed in arbitrary order, which is the default awk behavior.

"@ind_str_asc"
    Order by indices in ascending order compared as strings; this is the most basic sort. (Internally, array indices are always strings, so with ‘a[2*5] = 1’ the index is "10" rather than numeric 10.)


"@ind_num_asc"
    Order by indices in ascending order but force them to be treated as numbers in the process. Any index with a non-numeric value will end up positioned as if it were zero.

"@val_type_asc"
    Order by element values in ascending order (rather than by indices). Ordering is by the type assigned to the element (see Typing and Comparison). All numeric values come before all string values, which in turn come before all subarrays. (Subarrays have not been described yet; see Arrays of Arrays.)

"@val_str_asc"
    Order by element values in ascending order (rather than by indices). Scalar values are compared as strings. Subarrays, if present, come out last.

"@val_num_asc"
    Order by element values in ascending order (rather than by indices). Scalar values are compared as numbers. Subarrays, if present, come out last. When numeric values are equal, the string values are used to provide an ordering: this guarantees consistent results across different versions of the C qsort() function,41 which gawk uses internally to perform the sorting.

....
   
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP