awk笔记
来源:互联网 发布:java单元测试怎么做 编辑:程序博客网 时间:2024/05/01 08:38
awk -F":" '{ print "username: " $1 "/t/tuid:" $3 }' /etc/passwd
awk 'FS=":" {OFS="-"} {print NR "-->" $1, $2}' /etc/passwd
awk '{x=x+$3} {print NR, $3, x}' data
awk '{x=x+$3} END {print NR, $3, x}' data
awk '{x=x+$3} {print NR, $3, x | "sort -nr"}' data
FS="[[:space:]+]"
NF The number of fields in the current input record.
NR The total number of input records seen so far.
OFMT The output format for numbers, "%.6g", by default.
OFS The output field separator, a space by default.
ORS The output record separator, by default a newline.
awk中数组从1开始
for ( x in myarray ) {
print myarray[x]
}
当 awk 在数组下标之间轮转时,它不会依照任何特定的顺序
delete fooarray[1]
print length(mystring)
print index(mystring,"you")
print tolower(mystring)
print toupper(mystring)
print mystring // unchanged
mysub=substr(mystring,startpos,maxlen)
print match(mystring,/you/), RSTART, RLENGTH
RSTART 包含返回值(第一个匹配的位置),RLENGTH 指定它占据的字符跨度(如果没有找到匹配,则返回 -1)。
sub(regexp,replstring,mystring)
sub() 将替换第一个 regexp 匹配(如果有的话),gsub() 将执行全局替换
numelements=split("Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec",mymonths,",")
test.awk
---------
BEGIN { x=0 }
/^$/ { x=x+1 }
END { print "I found " x " blank lines. :)" }
---------------
awk -f test.awk inputfile
摘录自:
http://www-128.ibm.com/developerworks/cn/linux/shell/awk/awk-1/index.html
http://www-128.ibm.com/developerworks/cn/linux/shell/awk/awk-2/index.html
http://www-128.ibm.com/developerworks/cn/linux/shell/awk/awk-3/index.html
- awk笔记
- AWK 笔记
- awk笔记
- AWK笔记
- awk 笔记
- Awk笔记
- awk笔记
- awk笔记
- awk笔记
- awk笔记
- awk笔记
- awk笔记
- awk笔记
- awk笔记
- awk 笔记
- awk笔记
- awk sed 笔记--awk 1
- Sed&awk笔记之awk
- WebWork执行流程
- 令狐磊曾经很牛逼
- 手机铃声图片下载
- 勿以恶小而为之:Java编程的恶魔
- 注册博客成功!
- awk笔记
- Java初学者容易混淆的几个问题
- 编译Linux下的文件
- Solaris 常用命令和例子
- qt event
- [求助]RMI + 连接数据库问题 NULLPOINTEREXCEPTION
- [转帖]嫁人一定要嫁工资至少比你高3571.4元的男士
- Core Techniques And Algorithms In Game Programming
- SQL 索引相关链接