[RndTbl] Command line challenge: trim garbage from start and end of a file.

John Lange john at johnlange.ca
Wed Nov 10 12:15:35 CST 2010

I noticed that the sed version was much faster than the grep hack I
tried ( all those pipes!) but I didn't time it.

All things considered, I award "awk" the prize of "most elegant" for
its 3 less characters in the command string and slight performance

Thanks guys!


On Wed, Nov 10, 2010 at 11:56 AM, Sean Walberg <sean at ertw.com> wrote:
> Adam and I were having an offline discussion, and some testing shows that
> AWK outperforms SED by a slight margin:
> [sean at bob tmp]$ W=/usr/share/dict/words
> [sean at bob tmp]$ (tail -1000 $W; echo output start; cat $W; echo output end;
> head -1000 $W) > infile
> [sean at bob tmp]$ wc -l infile
> 481831 infile
> [sean at bob tmp]$ time awk '/output start/,/output end/' < infile > /dev/null
> real    0m0.411s
> user    0m0.393s
> sys     0m0.016s
> [sean at bob tmp]$ time  sed -n '/output start/,/output end/p' < infile >
> /dev/null
> real    0m0.678s
> user    0m0.631s
> sys     0m0.029s
> I ran it a bunch more times and the results were similar.  YMMV, benchmarks
> are lies, etc.
> Sean
> On Wed, Nov 10, 2010 at 11:32 AM, Gilles Detillieux
> <grdetil at scrc.umanitoba.ca> wrote:

John Lange

More information about the Roundtable mailing list