Awk Command Daily Work Summary

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

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

02/26/2019

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

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

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

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.code

02/28/2019

Print last column separated by spaceip

awk '{print $NF}'
相關文章
相關標籤/搜索