Adding to the front of a line

Florian Diesch diesch at spamfence.net
Wed Jan 21 19:29:05 UTC 2009


Matthew Flaschen <matthew.flaschen at gatech.edu> wrote:

> David Fox wrote:
>> On Tue, Jan 20, 2009 at 3:37 AM, Florian Diesch <diesch at spamfence.net> wrote:
>>> Using "seq 1 1000000 " as input the shell codes needs about 18s here
>>> while sed needs about 7s.
>> 
>> 
>> I'm not sure that is a fair test. Sure, bash is interpreted, but how
>> much "interpretation" really is done by a simple 'seq 1 1000000'?
>> Probably not a whole lot, compared to something like a for/next loop
>> in the old interpreted Basic machines.
>
> I don't think that's what Florian meant, and it's not what I did.  I did:
>
> seq 1 1000000>sites.txt
> time (while read site; do echo "127.0.0.1 $site"; done <sites.txt
>>output_file.txt)
> time (sed 's/^/127.0.0.1 /' <sites.txt >output_file.txt)
>
> In other words, the sequence is used as input, but not timed.


I did 
 time sh -c 'seq 1 1000000 | while read site; do echo "127.0.0.1 $site"; done > /dev/null'
 time sh -c 'seq 1 1000000 | sed "s/^/127.0.0.1 /" > /dev/null'

That avoids disk I/O so I don't have to care about file caches etc.




   Florian
-- 
<http://www.florian-diesch.de/>
-----------------------------------------------------------------------
**  Hi! I'm a signature virus! Copy me into your signature, please!  **
-----------------------------------------------------------------------




More information about the ubuntu-users mailing list