注册 登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

随机过程

http://superware.blog.163.com

 
 
 

日志

 
 

Selections in AWK  

2015-01-15 21:08:55|  分类: 默认分类 |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |

1. Selection by Comparison

awk '$3 > 0 {printf("%s %.2f %.2f\n", $1, $2, $3)}' data
The comparison $3 > 0 is to decide which field is to be selected.


2. Selection by Computation

awk '$2*$3 > 50 {printf("$%.2f for %s\n", $2*$3, $1)}' data

The computation $2*$3 > 0 is to decide which field is to be selected.

3. Selection by Text Content

        Besides numeric tests, you can select input lines that contain specific words or phrases. This program prints all lines in which the first field is Susie:

$1 == "Susie"

as the following:

awk '$1 == "Susie" {printf("%s %.2d %.2d\n", $1, $2, $3)}' data


The operator == tests for equality. You can also look for text containing any of a set of letters, words, and phrases by using patterns called regular expressions.  This pattern select all lines that contain Susie anywhere:

/Susie/

and the program is as the following

awk '/Susie/ {printf("%s %.2d %.2d\n", $1, $2, $3)}' data


4. Combination of Patterns

        Patterns can be combined with parentheses and the logical operators &&, ||, and !, which stand for AND, OR, and NOT. The expression

$2 >= 4 || $3 >= 20

select those lines where $2 is at least 4 or $3 is at least 20, the program can be given as:

awk '$2 >= 4 || $3 >= 20 {printf("%s %.2f %.2f\n", $1, $2, $3)}' data

  评论这张
 
阅读(57)| 评论(0)
推荐

历史上的今天

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2017