sed/awk, instead of Perl

Walt Pawley walt at wump.org
Sat Aug 23 00:18:15 UTC 2008


At 9:59 AM +0200 8/22/08, Oliver Fromme wrote:

> - The perl command you wrote above is pretty much a sed
>   command anyway (except you incorrectly used non-portable
>   regular expression syntax).  Why use perl to execute a
>   sed command?

At the risk of beating this to death, I just happened to
stumble on a real world example of why one might want to use
Perl for sed-ly stuff. I wanted to pull off the accessor's
address from each line of an Apache access log file. So, I
figured after this discussion that sed was the way to go. Then
I got curious and did the following:

wump$ ls -l Desktop/klog
-rw-r--r--  1 wump  1001  52753322 22 Aug 16:37 Desktop/klog
wump$ time sed "s/ .*//" Desktop/klog > kadr1

real    0m10.800s
user    0m10.580s
sys     0m0.250s
wump$ time perl -pe 's/ .*//' Desktop/klog > kadr2

real    0m0.975s
user    0m0.700s
sys     0m0.270s
wump$ cmp kadr1 kadr2
wump$

Why disparity in execution speed? Beats me, but my G5's fans
started to take off running the sed command. I don't think the
Perl command took long enough to register thermally. Curious.

FWIW: I did this with an older version of Mac OS X, rather
FreeBSD so it could easily not show the same results if I moved
the log file to a FreeBSD box and did it there.
-- 

Walter M. Pawley <walt at wump.org>
Wump Research & Company
676 River Bend Road, Roseburg, OR 97470
         541-672-8975


More information about the freebsd-questions mailing list