Re: [CentOS] Define an alias with an embeded awk command error ?
Am 06.03.2010 09:47, schrieb sync: > Hi, guys: > >I'm trying to define an alias in .cshrc with the embeded awk command, > like this : > > alias checketh0 "ip add ls eth0 |awk '/inet/{print $2}' |sed -n '1p' " > > Then i run "source ~/.cshrc" and run "checketh0" command in the terminal , > but the result is the following : > >" inet 192.168.18.18/24 brd 192.168.18.255 scope global eth0" > > but i want this result : > 192.168.18.18/24 > > > How do I do it ? Any help will be highly appreciated. > > > Thanks for you help ~ Within your awk statement the "$2" is eaten and thus awk prints the whole line. You can bypass this using following in your .cshrc set eth0=`/sbin/ip addr ls eth0 | awk '/inet/ { print $2; exit }'` alias checketh0 "echo $eth0" Alexander ___ CentOS mailing list CentOS@centos.org http://lists.centos.org/mailman/listinfo/centos
[CentOS] Define an alias with an embeded awk command error ?
Hi, guys: I'm trying to define an alias in .cshrc with the embeded awk command, like this : alias checketh0 "ip add ls eth0 |awk '/inet/{print $2}' |sed -n '1p' " Then i run "source ~/.cshrc" and run "checketh0" command in the terminal , but the result is the following : " inet 192.168.18.18/24 brd 192.168.18.255 scope global eth0" but i want this result : 192.168.18.18/24 How do I do it ? Any help will be highly appreciated. Thanks for you help ~ ___ CentOS mailing list CentOS@centos.org http://lists.centos.org/mailman/listinfo/centos
Re: [CentOS] Define an alias with an embeded awk command
m.r...@5-cent.us wrote: >> m.r...@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? > It wasn't an attack - and the one sed command does the same thing with an even more lightweight program. And perl could do it without running ifconfig. -- Les Mikesell lesmikes...@gmail.com ___ CentOS mailing list CentOS@centos.org http://lists.centos.org/mailman/listinfo/centos
Re: [CentOS] Define an alias with an embeded awk command
> m.r...@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
Re: [CentOS] Define an alias with an embeded awk command
m.r...@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 lesmikes...@gmail.com ___ CentOS mailing list CentOS@centos.org http://lists.centos.org/mailman/listinfo/centos
Re: [CentOS] Define an alias with an embeded awk command
> On Mon, Dec 14, 2009 at 7:20 PM, Majian 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 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
Re: [CentOS] Define an alias with an embeded awk command
On Mon, Dec 14, 2009 at 7:20 PM, Majian 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
Re: [CentOS] 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
Re: [CentOS] Define an alias with an embeded awk command
On Mon, Dec 14, 2009 at 8:54 PM, Andrew Harley 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
Re: [CentOS] 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` smime.p7s Description: S/MIME Cryptographic Signature ___ CentOS mailing list CentOS@centos.org http://lists.centos.org/mailman/listinfo/centos
Re: [CentOS] 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 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
Re: [CentOS] 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
[CentOS] 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