免费注册 查看新帖 |

Chinaunix

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

awk帮忙解释 已解决 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2009-09-01 11:50 |只看该作者 |倒序浏览
data:
Guy Quigley916) 343-6410:250:100:175
Dan Savage406) 298-7744:450:300:275
Nancy McNeil206) 548-1278:250:80:75
John Goldenrod916) 348-4278:250:100:175
Chet Main510) 548-5258:50:95:135
Tom Savage40 926-3456:250:168:200

awk -F: '{m3=($3 >= 200) ? $3 : 0;m4=($4 >= 200) ? $4 : 0;m5=($5 >= 200) ? $5 : 0;  print $1":",m3,m4,m5 }'

打印后面三个月 某个月捐款超过200的就打印  低于200的显示为0
结果

Susan Dalsass: 250 0 0
Archie McNichol: 250 0 0
Jody Savage: 0 0 0
Guy Quigley: 250 0 0
Dan Savage: 450 300 275

之前学习awk的时候做的练习题目,今天翻出来看,发现看不懂了.
请帮忙解释下.

? $3 : 0 什么意思?

[ 本帖最后由 ncache 于 2009-9-1 12:05 编辑 ]

论坛徽章:
8
摩羯座
日期:2014-11-26 18:59:452015亚冠之浦和红钻
日期:2015-06-23 19:10:532015亚冠之西悉尼流浪者
日期:2015-08-21 08:40:5815-16赛季CBA联赛之山东
日期:2016-01-31 18:25:0515-16赛季CBA联赛之四川
日期:2016-02-16 16:08:30程序设计版块每日发帖之星
日期:2016-06-29 06:20:002017金鸡报晓
日期:2017-01-10 15:19:5615-16赛季CBA联赛之佛山
日期:2017-02-27 20:41:19
2 [报告]
发表于 2009-09-01 11:54 |只看该作者

  1. 5.12 Conditional Expressions

  2. A conditional expression is a special kind of expression that has three operands. It allows you to use one expression's value to select one of two other expressions. The conditional expression is the same as in the C language, as shown here:

  3.      selector ? if-true-exp : if-false-exp

  4. There are three subexpressions. The first, selector, is always computed first. If it is “true” (not zero or not null), then if-true-exp is computed next and its value becomes the value of the whole expression. Otherwise, if-false-exp is computed next and its value becomes the value of the whole expression. For example, the following expression produces the absolute value of x:

  5.      x >= 0 ? x : -x
复制代码

论坛徽章:
5
2015年辞旧岁徽章
日期:2015-03-03 16:54:152015年迎新春徽章
日期:2015-03-04 09:50:282015年亚洲杯之朝鲜
日期:2015-03-13 22:47:33IT运维版块每日发帖之星
日期:2016-01-09 06:20:00IT运维版块每周发帖之星
日期:2016-03-07 16:27:44
3 [报告]
发表于 2009-09-01 11:55 |只看该作者

回复 #1 ncache 的帖子

条件赋值啰。

论坛徽章:
0
4 [报告]
发表于 2009-09-01 12:02 |只看该作者

回复 #2 waker 的帖子

明白了 满足前面的条件就赋值 不满足就赋:后面的值
我都不知道当时是在哪里看的   一点印象都没了

论坛徽章:
0
5 [报告]
发表于 2009-09-01 12:04 |只看该作者
你在C中看过吧?或者什么编程基础的书,呵呵
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP