LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Your use of AWK (https://www.linuxquestions.org/questions/linux-newbie-8/your-use-of-awk-4175502667/)

validator456 04-23-2014 04:27 AM

Your use of AWK
 
How useful is AWK for day-to-day practice? Is it useful to learn it? How often do you use it?

chrism01 04-23-2014 06:54 AM

Some people just use it for one-liners to eg extract one or more fields separated by random amts of space from a record.
Others write entire programs in it.
This may help http://www.grymoire.com/Unix/Awk.html

validator456 04-23-2014 07:07 AM

Thank you.

DavidMcCann 04-23-2014 11:28 AM

I've never used it in over a decade of using Linux. If you have a GUI, then the old command-line tools seem rather redundant, unless you already know them and are used to them.

metaschima 04-23-2014 11:39 AM

It is useful in many cases, especially complex text manipulation. However, bash is more useful overall. I use awk in about 30% of my scripts.

jpollard 04-23-2014 05:50 PM

I'll use awk if the problem needs less than about 50 lines to implement. If it looks like it will take more then I will use Perl, as it is faster than awk, and MUCH more flexible, with better diagnostics.

jlinkels 04-23-2014 06:40 PM

I use it for numerous one-time data processing projects. For example when I get a CSV file and I must process it on one or another way to include in a report.

For projects with a longer life time I use it often to transform CSV data or database output into something else. That something else is often SQL statements to get it onto a different database. Examples include radio program schedules from one format to another format. Database output to Google KML format. Database output to Latex.

I don't know if Perl would have been better for those purposes. I never learned it because of its incomprehensible syntax.

jlinkels

syg00 04-23-2014 08:31 PM

:p

I learned perl first, then some years later awk. Now-adays I would use awk every day, (new) perl maybe once a month if something big comes along. Bash a distant third because I keep having to look things up due to irregular usage.

validator456 04-24-2014 08:32 AM

Thank you.

catkin 04-24-2014 08:54 AM

I decided to learn awk before sed because it can do everything sed can do. Some things can be done more elegantly by sed but awk can do them. And, having already learned C, awk was easier.

Since the I have written some 1000+ line awk scripts -- for example for transforming CSV and LDIF files.

Now I'm comfortable with sed too and use whichever is best suited to the task.

Perl may be great but I cannot generate any enthusiasm for learning it. Reportedly it's easy to learn if you know C, regular expressions and shell script but first attempts were much more frustrating than first awk attempts. And it doesn't look nice :eek:

grail 04-24-2014 10:23 AM

I learnt awk because I raised a question about data that could be defined by a delimiter and was told this is the tool :)

As with others, the right tool for the job is best, but I would predominantly use awk for quick and short program manipulation and then switch to Ruby (catkin you might give this a try)
for larger tasks that require more finesse :)


All times are GMT -5. The time now is 03:08 PM.