美文网首页
Awk Command Daily Work Summary

Awk Command Daily Work Summary

作者: 海胆阶段 | 来源:发表于2019-03-01 14:47 被阅读0次

    This article used to walk you through some commonly awk usages , based on a real life scenario.

    ################################################################
    #   Date           Description
    #   02/28/2019     print last column
    #   02/26/2019     awk remote execution
    #
    ################################################################

    02/26/2019

    When use awk in script, may suffer shell unexpected expanding:

    ssh -o StrictHostKeyChecking=no sshrm1 "ifconfig eth0 | grep \"inet\" | awk '{print $2}'"
    

    Above will not get right data, instead preceding \ before $

    ssh -o StrictHostKeyChecking=no sshrm1 "ifconfig eth0 | grep \"inet\" | awk '{print \$2}'"
    

    Another method is awk the return value from ssh rather than wrap it in ssh command.

    02/28/2019

    Print last column separated by space

    awk '{print $NF}'
    

    相关文章

      网友评论

          本文标题:Awk Command Daily Work Summary

          本文链接:https://www.haomeiwen.com/subject/vnsduqtx.html