python vs awk for simple sysamin tasks
Roy Smith
roy at panix.com
Thu Jun 3 11:25:10 EDT 2004
Steve Lamb <grey at despair.dmiyu.org> wrote:
> > I'm sure you could replicate this functionality in python using things
> > like os.walk() and os.stat(), but why bother? The result would be no
> > better than the quick on-liners you've got above.
>
> Not true. The above one liners are two passes over the same data. With
> an appropriate script you could make one pass and get both results.
You may be right that a python script would be faster. The shell pipe
does make two passes over the data, not to mention all the pipe
overhead, and the binary -> ascii -> binary double conversion.
But does it matter? Probably not. Groveling your way through a whole
file system is pretty inefficient any way you do it. It's extremely
rare to find a sysadmin task where this kind of efficiency tweaking
matters. As long as the overall process remains O(n), don't sweat it.
> Sure you could do that in shell but I'm of the opinion that anything
> other than one liners should never be done in shell.
To a certain extent, you're right, but the two examples given really
were effectively one liners.
More information about the Python-list
mailing list