ITPub博客

首页 > Linux操作系统 > Linux操作系统 > [Shell] awk学习(2)-pattern{action}

[Shell] awk学习(2)-pattern{action}

原创 Linux操作系统 作者:tolilong 时间:2016-04-11 15:21:21 0 删除 编辑
其中如果pattern为true,则执行action
其中关系运算符包括>,<,==,!=,~,!~                             #~表示match,!~表示不match

例子:
[/tmp/test]# more tt11
A125 Jenny 100 210
A341 Dan 110 215
P158 Max 130 209
P148 John 125 220
A123 Linda 95 210

对A开头的薪资*1.05,小于100的按100算
[/tmp/test]# awk '$1~/^A/{$3*=1.05} $3<100{$3=100}{printf "%-10s%-10s%-8s%-8s\n",$1,$2,$3,$4}' tt11
A125      Jenny     105     210     
A341      Dan       115.5   215     
P158      Max       130     209     
P148      John      125     220     
A123      Linda     100     210 

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/24237320/viewspace-2079042/ ,如需转载,请注明出处,否则将追究法律责任。

下一篇: [Developer] Cube
请登录后发表评论 登录
全部评论

注册时间:2010-07-13

  • 博文量
    406
  • 访问量
    1208697