Re: Define an alias with an embeded awk command

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]



> On Mon, Dec 14, 2009 at 7:20 PM, Majian <jiannma@xxxxxxxxx> wrote:
>> But After  I  edit the command "alias checketh0  "echo `ifconfig eth0 |
>> grep
>> 'inet addr:' |awk '{print $2}' | cut -c 6-`"  in my .cshrc file
>> The screen displays this :
>> innet addr:192.168.7.24 Bcast:192.168.7.255 Mask :255.255.255.0
>
> I think you need to escape either the {} or $ in the awk command, or
> else not use it. Try:
>
> [root@ ~]# alias  checketh0 "ifconfig eth0 | grep 'inet addr:'|cut -d
> ':' -f 2|cut -f 1 -d ' '"
> [root@ ~]# checketh0
> 12.17.152.3
<snip>
Simpler, and more obvious to read:

/sbin/ifconfig eth0 | awk '{if ( $0 ~ /inet addr:/ ) {print substr($2,6)}}'

     mark "awk! awk!"

_______________________________________________
CentOS mailing list
CentOS@xxxxxxxxxx
http://lists.centos.org/mailman/listinfo/centos

[Index of Archives]     [CentOS]     [CentOS Announce]     [CentOS Development]     [CentOS ARM Devel]     [CentOS Docs]     [CentOS Virtualization]     [Carrier Grade Linux]     [Linux Media]     [Asterisk]     [DCCP]     [Netdev]     [Xorg]     [Linux USB]
  Powered by Linux