Awk Command Daily Work Summary

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}'
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容