awk:the most powerful utility tool in shell world.
来源:互联网 发布:网络语净化打卡的意思 编辑:程序博客网 时间:2024/06/11 00:56
1) FORMAT: awk 'pattern' filename
awk '{action}' filename
awk 'pattern {action}' filename
(a) awk '/Sally/ {print $1} filename
(b) ls -l |awk '$1 ~ /^d/ {print $0}'
(c) ls -l |awk '$1 !~ /^d/ {print $0}'
(d) awk ' /^(no|so)/' datafile
(e) awk -F: '$3==100||$4>=150' filename
2) send the shell's variable to nawk
for example:
Origin=ls -l
OriginB= `ls / |nawk -v swap="$Origin" '{print swap}'
3)nawk '$2 > 5 && $2 <= 15' filename
4)nawk 'BEGIN{while (getline < "/etc/passwd" > 0 )lc++; print lc}'
5)nawk '{print $1, $2 | "sort –r +1 –2 +0 –1 "}' names
6)cat /etc/passwd |awk -F: '{print NF}'
7)nawk '/^north/{count += 1; print count}' datafile
8)nawk '{ i = 1; while ( i <= NF ) { print NF, $i ; i++ } }' filename
9)nawk '{ for( i = 1; i <= NF; i++) print NF,$i }' filex
10)FORMAT
sub (regular expression, substitution string);
sub (regular expression, substitution string, target string)
nawk '{sub(/Mac/, "MacIntosh"); print}' filename
nawk '{sub(/Mac/, "MacIntosh", $1); print}' filename
11)nawk '{ print index("hollow", "low") }' filename
12)nawk '{ print length("hello") }' filename
13)nawk ' { print substr("Santa Claus", 7, 6 )} ' filename
14)nawk 'END{start=match("Good ole USA", /[A–Z]+$/); print start}'/
filename
15)nawk 'END{start=match("Good ole USA", /[A–Z]+$/);/
print RSTART, RLENGTH}' filename
16)awk 'BEGIN{split("12/25/2001",date,"/");print date[2]}' filename
- awk:the most powerful utility tool in shell world.
- The most distant way in the world
- THE MOST EXPENSIVE PIANO IN THE WORLD
- The most happiest country in the world
- The Adobe Photoshop Layers Book: Harnessing Photoshop's Most Powerful Tool, covers Photoshop CS3
- the most distant way in the world(Indian Tagore)
- HDU 3593 The most powerful force
- hdu-3593-The most powerful force
- HDOJ 3593 The most powerful force
- Most Powerful
- C++: The Most Powerful Language for .NET Framework Programming
- 树形DP(3) Hdu3593 The most powerful force (泛化背包)
- HDU 3593 The most powerful force 树形DP(背包)
- hdu 3593 The most powerful force (树形dp+背包)
- HDU 3593The most powerful force 树状dp
- 世界上最远的距离(The most distant way in the world)
- Search Driven Development: Five Reasons why search is your most powerful tool
- zoj 3471 Most Powerful
- 图片轮流显示
- PHP的面向对象编程=继承
- 笔记:Asp.Net应用程序性能优化
- 文件上传的实现(马马 2001年09月28日 17:14)PHP同样支持上传文件的功能,但并不是所有支持PHP的网站都支持此功能,特别是免费的网站。实现上传,首先要在HTML上加入上传文件的“<FORM>”表格。<form me
- 网络收藏夹
- awk:the most powerful utility tool in shell world.
- firmware
- 朦胧
- InstallShield X制作安装程序杂记(前言)
- 界面设计(struts)
- 唉,忙得都没时间写日志了。。
- Oracle DBA Interview Questions By B G
- CSS学习笔记一
- [转贴]Servlet/JSP配置详解