betabug... Sascha Welter

home english | home deutsch | Site Map | Sascha | Kontakt | Pro | Weblog | Wiki

02 June 2006

Burning Bytes Faster with sed

Logfile Unix Trivia Quiz

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 > outfile
This 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!


Posted by betabug at 10:49 | Comments (0) | Trackbacks (0)
ch athens
Life in Athens (Greece) for a foreigner from the other side of the mountains. And with an interest in digital life and the feeling of change in a big city. Multilingual English - German - Greek.
Main blog page
Recent Entries
Best of
Some of the most sought after posts, judging from access logs and search engine queries.

Apple & Macintosh:
Security & Privacy:
Misc technical:
Athens for tourists and visitors:
Life in general:
<< Driving into Athens by Night | Main | HelMUG Generalversammlung diesen Sonntag >>
Comments
There are no comments.
Trackbacks
You can trackback to: http://betabug.ch/blogs/ch-athens/373/tbping
There are no trackbacks.
Leave a comment