LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (http://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Will awk be able to handle all my requirements? (http://www.linuxquestions.org/questions/linux-newbie-8/will-awk-be-able-to-handle-all-my-requirements-4175436234/)

shivaa 11-08-2012 06:06 AM

Will awk be able to handle all my requirements?
 
Hello friends!
I have been working with shell scripts (sh/csh/ksh) and I am able to do most of my administrative tasks using it. But sometimes I need some extra tools like awk to make my scripts more effective & convienient. These days I am learning awk, as I believe that combinedly shell & awk will make those scripts more powerful. But I am not sure that can I write scripts independently in awk? Will awk be able to fulfill all my requirements of day-to-day admin tasks (I hope all you Sys. admins & Unix engineers know what day-to-day tasks we do as a Unix admin).
So my questions is, shall I go with in-depth knowledge of awk and shall I spent time in learning in-depth of awk? I already know it little bit, so it will be easy for me to learn it.
On the other hand, I don't want to spent time in learning perl or python, as I dont have that much time these days to learn, write scripts & implement it in live environment.
Any suggestions are most welcome!

Didier Spaier 11-08-2012 06:40 AM

Yes you can invoke awk independently.

The more I use it, the more I like it and there are a lot of things I used to do with bash that I now do with awk (gnu awk or gawk, as shipped in Slackware). It certainly is easier and faster to learn IMHO than perl or python, especially with a shell scripting background.

The time you will spend to learn awk won't be lost.

David the H. 11-08-2012 02:31 PM

As always, you need to choose the right tool for the right job, and that means knowing what the tools can and can't do.

awk is an advanced text processing language. If you do a lot of work extracting, editing, and reformatting text data from files or commands, then it will pay to learn how to use it. If, for example, you find yourself often chaining together strings of cut|grep|sed|etc., then they can generally be replaced with a single awk command. Stand-alone awk scripts can also often be used instead of combined shell+command scripts for text processing jobs (and will generally be more efficient in such cases).

But what awk isn't, is a general scripting tool. It won't replace the shell for things like file renaming or system maintenance. Although it does have a built-in ability to execute external commands, it's really more of a support feature for the main task of text processing, and isn't designed for general use.

So by all means do learn how to use awk. But don't think you need to dive deeply into it all at once. I suggest first taking enough time to learn what it can do, without worrying much about learning how to do it. Then you can decide how much time to put into studying it in detail. But in the end it's just another system tool, and the more familiar you are with it the more you'll be able to do with it.

Here are a few useful awk references:
http://www.grymoire.com/Unix/Awk.html
http://www.gnu.org/software/gawk/man...ode/index.html
http://www.pement.org/awk/awk1line.txt
http://www.catonmat.net/blog/awk-one...ined-part-one/

The first one is probably the best for getting an overall view of the command.


BTW, another benefit of studying things like this is that the concepts you learn in one language very often translate over and help you in learning others as well. Much of awk syntax comes from C, which has also influenced many other languages and commands. I believe that learning awk has also improved my scripting ability in general.

shivaa 11-08-2012 09:17 PM

Many thanks to David and Didier. I am going to learn it.. right now!


All times are GMT -5. The time now is 08:49 AM.