[prev in list] [next in list] [prev in thread] [next in thread] 

List:       gentoo-user
Subject:    Re: [gentoo-user] Re: OT: global search and replace
From:       Billy Holmes <billy () gonoph ! net>
Date:       2004-09-10 14:54:40
Message-ID: 4141C030.5070109 () gonoph ! net
[Download RAW message or body]

Alexander Skwar wrote:

> Okay, and how does that differ from sed? If you'd read the man page
> of sed, you'd find:

it's better because perl starts with a "lower" letter than sed.

> Yes. That block's redundant.

seriously, I didn't read the man page. I just inferred such behavior 
from your shell code. Still, perl will allow you much more powerful file 
alterations, so it's just good to know that it's out there.

perl -i -p -MSocket -e '
if (m%http://(\d{0,3}\.\d{0,3}\.\d{0,3}\.\d{0,3})%)
{
   $name=gethostbyaddr(inet_aton($1),AF_INET);
   s%http://$1%http://$name%g unless ($name eq "");
}
' *.html

this would read in all html files, find all URL references that are 
quad-ip addresses, look them up and replace them with their names. 
Useful if you have old html or code that in hindsight realize should 
have used names rather than hard-coded ip addresses.

So, in the problem he listed, sed would work perfectly. In fact, sed 
worked great for another problem post on this list, where someone needed 
certain blocks of an email to be extracted automagically. Sed made that 
really easy - a one liner. Perl would have required at least two lines - 
probably more - to do the same thing.

--
gentoo-user@gentoo.org mailing list

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic