FAQ Search Today's Posts Mark Forums Read
» Video Reviews

» Linux Archive

Linux-archive is a website aiming to archive linux email lists and to make them easily accessible for linux users/developers.


» Sponsor

» Partners

» Sponsor

Go Back   Linux Archive > CentOS > CentOS

 
 
LinkBack Thread Tools
 
Old 12-15-2009, 03:40 AM
Majian
 
Default Define an alias with an embeded awk command

Hi ,all :

I'm trying to define an alias with an embeded awk command:

alias checketh0* `ifconfig eth0 |grep 'inet addr:' |awk '{prinrt $2}' |cut -c 6- `

After* I edit it in the* .cshrc file and run "source .cshrc" , I run the "checketh0" command in the terminal ,

the screen displays the "192.168.7.24: Command not found "


Why does is it ?Any help will be highly appreciated.



note: I'm using csh* shell.









Thanks for you help.

_______________________________________________
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos
 
Old 12-15-2009, 03:54 AM
Andrew Harley
 
Default Define an alias with an embeded awk command

On 15/12/09 15:40, Majian wrote:
Hi ,all :



I'm trying to define an alias with an embeded awk command:



alias checketh0* `ifconfig eth0 |grep 'inet addr:' |awk '{prinrt $2}'
|cut -c 6- `



After* I edit it in the* .cshrc file and run "source .cshrc" , I run
the "checketh0" command in the terminal ,

the screen displays the "192.168.7.24: Command not found "





Why does is it ?Any help will be highly appreciated.



note: I'm using csh* shell.


Hi Majian,



It's not an issue with awk but with the way the alias is interpreted.
It tries to run the result of the commands in between the ` ` as a
command itself. To get around it, try:



# alias checketh0="echo `ifconfig eth0 | grep 'inet addr:' |awk '{print
$2}' | cut -c 6-`"



Cheers,



Andrew



_______________________________________________
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos
 
Old 12-15-2009, 04:20 AM
Majian
 
Default Define an alias with an embeded awk command

Thanks for your advice ~
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* just want to the "192.168.7.24"


*Maybe is it the awk command error?


On Tue, Dec 15, 2009 at 12:54 PM, Andrew Harley <andrew@promed.com.au> wrote:







On 15/12/09 15:40, Majian wrote:
Hi ,all :



I'm trying to define an alias with an embeded awk command:



alias checketh0* `ifconfig eth0 |grep 'inet addr:' |awk '{prinrt $2}'
|cut -c 6- `



After* I edit it in the* .cshrc file and run "source .cshrc" , I run
the "checketh0" command in the terminal ,

the screen displays the "192.168.7.24: Command not found "





Why does is it ?Any help will be highly appreciated.



note: I'm using csh* shell.


Hi Majian,



It's not an issue with awk but with the way the alias is interpreted.
It tries to run the result of the commands in between the ` ` as a
command itself. To get around it, try:



# alias checketh0="echo `ifconfig eth0 | grep 'inet addr:' |awk '{print
$2}' | cut -c 6-`"



Cheers,



Andrew




_______________________________________________

CentOS mailing list

CentOS@centos.org

http://lists.centos.org/mailman/listinfo/centos




_______________________________________________
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos
 
Old 12-15-2009, 05:58 AM
Larry Brower
 
Default Define an alias with an embeded awk command

On 12/14/2009 11:20 PM, Majian wrote:

echo `ifconfig eth0 | grep 'inet addr:' |awk '{print $2}' | cut -c 6-


echo `ip addr |grep inet|grep -v 127.0.0.1|awk '{print $2}'|cut -d/ -f1`



_______________________________________________
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos
 
Old 12-15-2009, 02:35 PM
Bart Schaefer
 
Default Define an alias with an embeded awk command

On Mon, Dec 14, 2009 at 8:54 PM, Andrew Harley <andrew@promed.com.au> wrote:
>
> It's not an issue with awk but with the way the alias is interpreted. It
> tries to run the result of the commands in between the ` ` as a command
> itself. To get around it, try:
>
> # alias checketh0="echo `ifconfig eth0 | grep 'inet addr:' |awk '{print $2}' | cut -c 6-`"

Er, no, the double quotes will mean that the backtick command is
expanded at the time the alias is defined rather than at the time it
is run. So you'll get the ifconfig output from the time the shell
started, always.

You want

alias checketh0 'echo `ifconfig eth0 | grep "inet addr:" |awk
'{print $2}' | cut -c 6-`'
_______________________________________________
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos
 
Old 12-15-2009, 02:36 PM
Bart Schaefer
 
Default Define an alias with an embeded awk command

(Please pardon gmail's stupid line wrapping in that last example.
Should be all one line.)
_______________________________________________
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos
 
Old 12-15-2009, 06:23 PM
Dave
 
Default Define an alias with an embeded awk command

On Mon, Dec 14, 2009 at 7:20 PM, Majian <jiannma@gmail.com> 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

Note that I did not use any '`' marks. The example is on the command
line, not in .cshrc, but I hope it will work in that context anyhow.

This is a bit OT, should probably have OT in the subject?

HTH!
Dave
_______________________________________________
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos
 
Old 12-15-2009, 06:56 PM
 
Default Define an alias with an embeded awk command

> On Mon, Dec 14, 2009 at 7:20 PM, Majian <jiannma@gmail.com> 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@centos.org
http://lists.centos.org/mailman/listinfo/centos
 
Old 12-15-2009, 07:44 PM
Les Mikesell
 
Default Define an alias with an embeded awk command

m.roth@5-cent.us wrote:
>
> Simpler, and more obvious to read:
>
> /sbin/ifconfig eth0 | awk '{if ( $0 ~ /inet addr:/ ) {print substr($2,6)}}'

That's only obvious to the couple of people who speak awk... (Probably
about the same number that use the C shell that started this problem).

With more generic regexps it would be:

ifconfig eth0 |sed -n -e 's/(.*inet addr([0-9.]*)(.*)/2/p'

--
Les Mikesell
lesmikesell@gmail.com



_______________________________________________
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos
 
Old 12-15-2009, 08:07 PM
 
Default Define an alias with an embeded awk command

> m.roth@5-cent.us wrote:
>>
>> Simpler, and more obvious to read:
>>
>> /sbin/ifconfig eth0 | awk '{if ( $0 ~ /inet addr:/ ) {print
>> substr($2,6)}}'
>
> That's only obvious to the couple of people who speak awk... (Probably
> about the same number that use the C shell that started this problem).
>
> With more generic regexps it would be:
>
> ifconfig eth0 |sed -n -e 's/(.*inet addr([0-9.]*)(.*)/2/p'

Right, and that's obvious to the meanest intelligence, while "if what I
read in has this, then print this part of that field" is sooo complicated.

Are you willing to agree to differ, and stop attacking me, when I give one
awk script to replace 3-4 commands?

mark

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

Thread Tools




All times are GMT. The time now is 04:19 AM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright 2007 - 2008, www.linux-archive.org