linux 三剑客之awk总结
2024-09-21 12:41:28
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
最新文章
- COGS746. [网络流24题] 骑士共存
- Windows Internal Database Service Pack 4 x64 Edition (KB2463332)安装失败
- Sublime Text 3使用指南(2)——快捷键
- View通用
- 矩阵求逆算法及程序实现(C++)
- Linux内核system_call中断处理过程
- spring 下载地址
- bjui给出的一个标准应用的首页
- SharePoint 2013 开发——开发并部署Provider-hosted APP
- 一步步学习ASP.NET MVC3 (5)——View从Action中获得数据
- 关于Sublime text 2中Emmet的安装 _html:xt无效
- [问题解决] initAndListen: 10309 Unable to create/open lock file: /data/db/mongod.lock
- 从头开始学JavaScript (七)——函数
- Python 标准类库- 因特网协议于支持之UUID
- IISExpress配置使其能通过IP访问方法
- 20175314 《Java程序设计》第八周学习总结
- nginx介绍(三) 配置篇
- linux命令之kill篇
- CDialogEx::OnPaint()的问题,或者为什么在对话框程序的OnPaint中绘图无效的问题
- 识别图片验证码的三种方式(scrapy模拟登陆豆瓣网)
热门文章
- Fire Game (FZU 2150)(BFS)
- 响应式web布局
- BeetleX之快速构建Web多房间聊天室
- Windows上redis下载与安装
- BZOJ1123 BLO
- GLSL语法入门
- System 源码阅读
- 01 numpy库(一)
- Systemd 指令
- 【例3】设有关系模式R(A, B, C, D, E)与它的函数依赖集F={A→BC, CD→E, B→D, E→A},求R的所有候选键。 解题思路: