AWK解释awk -F'AUTO_INCREMENT =''NF == 1 {print“0”; next} {sub(/。* /,“”,$ 2); print $ 2}'

时间:2013-11-21 19:39:24

标签: linux bash shell awk sh

我在工作中经历了一些简单的bash脚本,这是其他人在一个月前写的,我发现了这一行:

| awk -F'AUTO_INCREMENT=' 'NF==1{print "0";next}{sub(/ .*/,"",$2);print $2}'

有人可以帮助我用简单的词语解释这一行。谢谢!

1 个答案:

答案 0 :(得分:2)

awk -F'AUTO_INCREMENT=' '     # Set 'AUTO_INCREMENT=' as a field separator
    NF==1 {                   # If number of fields is one i.e. a blank line
      print "0";              # print '0'
      next                    # Go to next record i.e. skip following code  
    }
    {
      sub(/ .*/,"",$2);       # Delete anything after a space in the second field 
      print $2                # Print the second field 
     }'

示例

示例输入

AUTO_INCREMENT=3

AUTO_INCREMENT=10 20 30 foo bar

输出

3
0
10