On Mon, May 22, 2000 at 07:53:54PM -0700, Timothy L. Bolz wrote:
>
> I'm trying to get my ppp ip address from this script
>
> PPP_DEV="ppp0"
> /sbin/ifconfig |grep -A $PPP_DEV\| awk '/inet/{print$2}'| sed -es/addr://
>
> it gives me the local and the ppp0. I wanted to use it to put my ip
> address in my page which then friends could check out my web pages on my
> system rather than efn"s. I have appache going on my system here at home.
> I did a search on ip extracting and found very little on it.
>
I offer the following two scripts as candidates:
(perl)
ifconfig ppp0 | \
perl -e 'while (<>) {
if(m/inet addr:([0-9.]+)/) {
print "$1\n"
}
}'
(awk)
ifconfig ppp0 | \
awk '/inet addr:[0-9.]+/ {
sub (/.*inet addr:/,"");
match ($0, /[0-9.]+/);
print substr($0, RSTART, RLENGTH); }'
Usually, if one is using Perl or awk, there is no need for grep or
sed. I suggest avoiding sed entirely; it is one of the most difficult
of the text filters, and I think awk and perl do everything it can do.
--
Randolph Fritz
Eugene, Oregon, USA