AWK

1.begin end使用

cat /tmp/passwd |awk -F ':' 'BEGIN {print "hello"} {print $1"\t"$3} END {print "ending"}'

2.匹配

[root@zeus tmp]# cat /tmp/passwd |awk -F ':' 'BEGIN {print "hello"} /root/{print $1"\t"$3} END {print $2}'

hello

root    0

operator        11

x

3.printf

[root@zeus tmp]# cat /tmp/passwd |awk -F ':' '/root/{printf("%s %s %s\n",NR,$1,$2)}'

1 root x

10 operator x

4.变量:

[root@zeus tmp]# ls -l|awk 'BEGIN {row=0;} {row++;} END {printf("total:\t%s\n",row)}'

total:  24

5.判断

[root@zeus tmp]# ls -l|awk 'BEGIN {row=0;} {print $3;if($3=="root"){row++;}} END {printf("total:\t%s\n",row)}'

6.循环

awk -F ':' 'BEGIN {count=0;} {name[count] = $1;count++;}; END{for (i = 0; i < NR; i++) print i, name[i]}' /etc/passwd

最新文章

  1. COGS746. [网络流24题] 骑士共存
  2. Windows Internal Database Service Pack 4 x64 Edition (KB2463332)安装失败
  3. Sublime Text 3使用指南(2)——快捷键
  4. View通用
  5. 矩阵求逆算法及程序实现(C++)
  6. Linux内核system_call中断处理过程
  7. spring 下载地址
  8. bjui给出的一个标准应用的首页
  9. SharePoint 2013 开发——开发并部署Provider-hosted APP
  10. 一步步学习ASP.NET MVC3 (5)——View从Action中获得数据
  11. 关于Sublime text 2中Emmet的安装 _html:xt无效
  12. [问题解决] initAndListen: 10309 Unable to create/open lock file: /data/db/mongod.lock
  13. 从头开始学JavaScript (七)——函数
  14. Python 标准类库- 因特网协议于支持之UUID
  15. IISExpress配置使其能通过IP访问方法
  16. 20175314 《Java程序设计》第八周学习总结
  17. nginx介绍(三) 配置篇
  18. linux命令之kill篇
  19. CDialogEx::OnPaint()的问题,或者为什么在对话框程序的OnPaint中绘图无效的问题
  20. 识别图片验证码的三种方式(scrapy模拟登陆豆瓣网)

热门文章

  1. Fire Game (FZU 2150)(BFS)
  2. 响应式web布局
  3. BeetleX之快速构建Web多房间聊天室
  4. Windows上redis下载与安装
  5. BZOJ1123 BLO
  6. GLSL语法入门
  7. System 源码阅读
  8. 01 numpy库(一)
  9. Systemd 指令
  10. 【例3】设有关系模式R(A, B, C, D, E)与它的函数依赖集F={A→BC, CD→E, B→D, E→A},求R的所有候选键。 解题思路: