免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
楼主: luck_libiao
打印 上一主题 下一主题

关于awk包含空格以及=做为分隔符的问题! [复制链接]

论坛徽章:
0
11 [报告]
发表于 2010-06-12 12:02 |只看该作者
本帖最后由 luck_libiao 于 2010-06-12 14:38 编辑

回复 8# lkk2003rty


    没有报错的!不过也少了一个}
awk -F  "[= ]" '{ a[$8]++} END{for (b in a) {print b,a} }' billtype_Mem.sql 执行的结果为:
55434744 1
56604049 1
10735231 1
54653178 1
55917492 1
11433573 1
53102121 1
56628142 1
10103998 1
53956299 1
54852113 1
55486244 1
56056673 1
56391452 1
54254460 1
50775650 1
53102118 1
53420560 1
56783193 1
54653202 1
54022999 1
54016439 1
10337832 1
50369194 1
但是我之前执行却没有结果,汗。。。
当时是想测试下:awk -F "[= ]" ' BEGIN { OFS=" " } {print }' billtype_Mem.sql  ;但是并没有按 空格做为分隔符来输出!
还是输出原数据!

论坛徽章:
1
水瓶座
日期:2013-11-04 13:16:13
12 [报告]
发表于 2010-06-12 12:13 |只看该作者
本帖最后由 howge 于 2010-06-12 12:19 编辑

回复 1# luck_libiao


    awk -F  "=| " '{ a[$8]++} END{for (b in a) {print b,a} }' file
这样可以吗?


重新编辑了,语法错误吧!! 你少个 “}”

论坛徽章:
0
13 [报告]
发表于 2010-06-12 12:44 |只看该作者
回复 11# luck_libiao
  1. [oracle@s12071 ~]$ awk -F "[= ]" '{a[$8]++}END{for(cnt in a)print cnt,a}' file
  2. awk: cmd. line:1: (FILENAME=file FNR=8) fatal: attempt to use array `a' in a scalar context
  3. [oracle@s12071 ~]$ awk --version
  4. GNU Awk 3.1.3
  5. Copyright (C) 1989, 1991-2003 Free Software Foundation.

  6. This program is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 2 of the License, or
  9. (at your option) any later version.

  10. This program is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13. GNU General Public License for more details.

  14. You should have received a copy of the GNU General Public License
  15. along with this program; if not, write to the Free Software
  16. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  17. [oracle@s12071 ~]$
复制代码

论坛徽章:
0
14 [报告]
发表于 2010-06-12 12:45 |只看该作者
回复 11# luck_libiao


    如果有空格分隔符你覺得應該是什麽樣的。。。。。。。。。

求职 : 技术支持/维
论坛徽章:
0
15 [报告]
发表于 2010-06-12 12:55 |只看该作者
提示: 作者被禁止或删除 内容自动屏蔽

论坛徽章:
0
16 [报告]
发表于 2010-06-12 13:31 |只看该作者
本帖最后由 ywlscpl 于 2010-06-12 13:32 编辑

awk -F "subscriberkey=" '{split($2,m," +");a[m[1]]++}END{for (j in a) print j,a[j]}' file

论坛徽章:
0
17 [报告]
发表于 2010-06-12 14:32 |只看该作者
本帖最后由 luck_libiao 于 2010-06-12 14:41 编辑

回复 13# lkk2003rty


    但是在我的Unix系统上是可以运行的:
awk -F  "[= ]" '{ a[$8]++} END{for (b in a) {print b,a} }' billtype_Mem.sql
55434744 1
56604049 1
10735231 1
54653178 1
55917492 1
11433573 1
53102121 1
56628142 1
10103998 1
53956299 1
54852113 1
55486244 1
56056673 1
56391452 1
54254460 1
50775650 1
53102118 1
53420560 1
56783193 1
54653202 1
54022999 1
54016439 1
10337832 1
50369194 1

论坛徽章:
0
18 [报告]
发表于 2010-06-12 14:42 |只看该作者
回复 11# luck_libiao


    怎么我写的东西,少了[]号呢!原语句在附件的图中!

新建 BMP 图像.jpg (750.05 KB, 下载次数: 18)

新建 BMP 图像.jpg

论坛徽章:
0
19 [报告]
发表于 2010-06-12 14:46 |只看该作者
回复 12# howge


    这样也是可以的!貌似使用awk的通配符和[]均是可以的,awk还有很多值得专研的东西!

新建 BMP 图像.jpg (1.25 MB, 下载次数: 18)

新建 BMP 图像.jpg

论坛徽章:
0
20 [报告]
发表于 2010-06-12 15:11 |只看该作者
提示: 作者被禁止或删除 内容自动屏蔽
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP