LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 562|回复: 1

请教大家一个AWK的脚本!

[复制链接]
发表于 2005-7-21 20:56:53 | 显示全部楼层 |阅读模式
最近移植djbdns,里面有一个AWK的脚本,我看不太懂,想请大家帮忙分析一下,看看主要是实现什么功能的,多谢大家了!

awk -F: '
  BEGIN { OFS=":" }
  {
    if ($5 == "tx") next
    if ($5 == "A") {
      print "glue",$6,$3,$4,"answer",$6" A "$7
      next
    }
    if ($5 == "NS") {
      print "glue",$6,$3,$4,"answer",$6" NS "$7
      next
    }
    print
  }
' | sort -t: +0 -2 +4 +3 -4 +2 -3 | uniq | awk -F: '
  {
    type = $1
    q = $2
    c = $3
    ip = sprintf("%-16s",$4)

    if (q != lastq) { print ""; lastq = q }

    if ($5 == "ALERT") {
      result = "A\bAL\bLE\bER\bRT\bT:\b: " $6
    }
    else if ($5 == "answer") {
      if (index($6,q" ") == 1)
        $6 = substr($6,length(q) + 2)
      result = $6
    }
    else if ($5 == "see") {
      result = "see " $6
    }
    else if ($5 == "CNAME") {
      result = "CNAME "$6
    }
    else
      result = $5

    if (c != ".") {
      q = substr(q,1,length(q) - length(c))
      for (i = 1;i <= length(c);++i) {
        ci = substr(c,i,1)
        q = q "_\b" ci
      }
    }

    print type,q,ip,result
  }
'
发表于 2005-7-22 11:22:15 | 显示全部楼层
看不懂
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表