Burning Bytes Faster with sed
This morning's Unix trivia quiz from my friend Saad: What tool to use to chop down a logfile to list only entries after a certain date? Modern admins would likely pull out their Perl, Python, TCL, or other scripting language tool chest. My answer: There is a much, much faster tool for such a simple job. And it's a one liner too. The solution:
sed -n '/02\/Jun\/2006:08:47:14 +0200/,$ p' < infile > outfileThis will find the first line with that date/time in the logfile, then print this and any following lines. A bit of shell redirecting will push it all neatly into a new file.
Reply to the solution: "f* fast sed!" Tools that were written on 1Mhz class machines tend to be fast. It's interesting how e.g. Perl advocates say that using a tool like Perl is better than shell toolkit based solutions, because Perl doesn't need to spawn so many processes. But sed is so fast, you can spawn and run a couple of sed jobs while Perl is still waking up and scratching its camel ballz. Sometimes there is just the right tool for the job. Even though I use sed only very infrequently I managed with a little sed web help to come up with my oneliner while saad was still pushing {/} braces into Perl code... pwned!