【问题标题】:AWK interpretation awk -F'AUTO_INCREMENT=' 'NF==1{print "0";next}{sub(/ .*/,"",$2);print $2}'AWK 解释 awk -F'AUTO_INCREMENT=' 'NF==1{print "0";next}{sub(/.*/,"",$2);print $2}'
【发布时间】:2013-12-06 11:27:29
【问题描述】:

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

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

谁能帮我用简单的话解释一下这句话。谢谢!

【问题讨论】:

  • 为什么要更改原来的问题内容?您似乎想发布对问题的编辑,但同时您还尝试编辑我的答案。

标签: linux bash shell awk sh


【解决方案1】:
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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-01-30
    • 2022-01-25
    • 2021-04-05
    • 1970-01-01
    • 2015-11-01
    • 1970-01-01
    • 2017-06-11
    • 1970-01-01
    相关资源
    最近更新 更多