|NO.Z.00010|——————————|LinuxShell|——|Linux&Shell&字符截取和替换命令.V08|——|awk函数|
一、awk函数
### --- awk 编程也允许在编程时使用函数,
~~~ 在本小节我们讲讲 awk 的自定义函数。awk 函数的定义方法如下:
function 函数名(参数列表){
函数体
}
### --- 我们定义一个简单的函数,
~~~ 使用函数来打印 student.txt 的学员姓名和平均成绩,应该这样来写函数
### --- 定义函数 test,包含两个参数,函数体的内容是输出这两个参数的值
~~~ 调用函数 test,并向两个参数传递值。
[root@localhost ~]# awk 'function test(a,b) { printf a "\t" b "\n" }
{ test($2,$6) } ' student.txt
Name Average
Liming 87.66
Sc 85.66
Tg 91.66
Walter Savage Landor:strove with none,for none was worth my strife.Nature I loved and, next to Nature, Art:I warm'd both hands before the fire of life.It sinks, and I am ready to depart
——W.S.Landor
浙公网安备 33010602011771号