python vs awk for simple sysamin tasks
Donald 'Paddy' McCarthy
paddy3118 at netscape.net
Sat Jun 5 16:11:07 EDT 2004
Matthew Thorley wrote:
> My friend sent me an email asking this:
>
> > I'm attemtping to decide which scripting language I should master and
> > was wondering if it's possible to do
> > these unixy awkish commands in python:
> >
> > How to find the amount of disk space a user is taking up:
> >
> > find / -user rprice -fstype nfs ! -name /dev/\* -ls | awk '{sum+=$7};\
> > {print "User rprice total disk use = " sum}'
> >
> > How to find the average size of a file for a user:
> >
> > find / -user rprice -fstype nfs ! -name /dev/\* -ls | awk '{sum+=$7};\
> > {print "The ave size of file for rprice is = " sum/NR}'
>
> I wasn't able to give him an afirmative answer because I've never used
> python for things like this. I just spent the last while looking on
> google and haven't found an answer yet. I was hoping some one out there
> might have some thoughts ?
>
> thanks much
> -matthew
I think you will find that the examples could be re-written in python
(or perl), but assuming you have created the one liners above and so
know your way around 'the basics' then you would be most productive in
leaving a space for find and bash and sed and awk and grep ... for
mainly smaller scripts Python is not good for one liners but tends to be
easy to maintain.
I don't believe that you should abandon AWK once you learn Python,
especially if you do Sys-Admin work. Python has a broad range of uses
but it is not better than AWK in all cases, as I think others have shown
in the thread by giving a much longer Python version of an example.
Cheers, Paddy.
More information about the Python-list
mailing list