[英]awk function does not allow to return
i have functions in my awk script to parse lines contains certain words/characters 我在awk脚本中有函数来解析包含某些单词/字符的行
function tohyphen (o) {
split ($0,a,"to[-_]")
split (a[2],b,"-")
k=b[1]
p=b[2]
return k
}
function tospace (o) {
split ($0,a,"to ")
split (a[2],b,"-")
k=b[1]
p=b[2]
return k
}
funtion pipe (o) {
split ($0,a,"|")
split (a[2],b,"-")
x=b[1]
y=b[2]
return x
#return x
}
{
#if (match ($0, /to[-_]/))
if ($0 ~ /to[-_]/)
print "found to- for interface ", $1, " is ", tohyphen($0), "is ",p, " is ", $1="",$0
else if ($0 ~ /to /)
#(match ($0, /to /))
print "found to for interface", $1, " is ", tospace($0), " is ", p, " is ", $1="",$0
else if ($0 ~ /\|/)
# pipe($0)
print "found to for interface", $1, " is ",topipe($0), " is ", y, " is ", $1="",$0
else
print $1, $1="",$0
}
in the third function which just searches for a match to pipe it does not allow me return anything, giving me the error return is outside of function. 在第三个函数中,该函数仅搜索要传递给管道的匹配项,它不允许我返回任何内容,这给我带来了错误返回超出函数的范围。 any idea what could be the problem or any other way for me to run this. 任何想法可能是问题,还是我运行此问题的任何其他方式。
Try spelling function correctly! 尝试正确的拼写功能 ! You have funtion not function. 您没有功能。 Are you using an editor with syntax highlighting for awk
? 您是否正在使用带有语法突出显示awk
的编辑器? You can see from stackoverflows markup that funtion is not a reserved word. 从stackoverflows标记中可以看出,功能不是保留字。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.