LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 04-23-2014, 05:27 AM   #1
validator456
Member
 
Registered: Apr 2013
Location: Rotterdam, The Netherlands
Distribution: Crunchbang Linux
Posts: 135

Rep: Reputation: Disabled
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?
 
Old 04-23-2014, 07:54 AM   #2
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,240

Rep: Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324
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
 
Old 04-23-2014, 08:07 AM   #3
validator456
Member
 
Registered: Apr 2013
Location: Rotterdam, The Netherlands
Distribution: Crunchbang Linux
Posts: 135

Original Poster
Rep: Reputation: Disabled
Thank you.
 
Old 04-23-2014, 12:28 PM   #4
DavidMcCann
Senior Member
 
Registered: Jul 2006
Location: London
Distribution: CentOS, Salix
Posts: 4,158

Rep: Reputation: 1223Reputation: 1223Reputation: 1223Reputation: 1223Reputation: 1223Reputation: 1223Reputation: 1223Reputation: 1223Reputation: 1223
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.
 
Old 04-23-2014, 12:39 PM   #5
metaschima
Senior Member
 
Registered: Dec 2013
Distribution: Slackware
Posts: 1,982

Rep: Reputation: 490Reputation: 490Reputation: 490Reputation: 490Reputation: 490
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.
 
1 members found this post helpful.
Old 04-23-2014, 06:50 PM   #6
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,599

Rep: Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241
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.
 
1 members found this post helpful.
Old 04-23-2014, 07:40 PM   #7
jlinkels
Senior Member
 
Registered: Oct 2003
Location: Bonaire
Distribution: Debian Wheezy/Jessie/Sid, Linux Mint DE
Posts: 4,493

Rep: Reputation: 635Reputation: 635Reputation: 635Reputation: 635Reputation: 635Reputation: 635
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
 
1 members found this post helpful.
Old 04-23-2014, 09:31 PM   #8
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 14,832

Rep: Reputation: 1820Reputation: 1820Reputation: 1820Reputation: 1820Reputation: 1820Reputation: 1820Reputation: 1820Reputation: 1820Reputation: 1820Reputation: 1820Reputation: 1820


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.
 
1 members found this post helpful.
Old 04-24-2014, 09:32 AM   #9
validator456
Member
 
Registered: Apr 2013
Location: Rotterdam, The Netherlands
Distribution: Crunchbang Linux
Posts: 135

Original Poster
Rep: Reputation: Disabled
Thank you.
 
Old 04-24-2014, 09:54 AM   #10
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,576
Blog Entries: 31

Rep: Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195
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
 
1 members found this post helpful.
Old 04-24-2014, 11:23 AM   #11
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,243

Rep: Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684
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
 
2 members found this post helpful.
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
turning awk command line entries into awk scripts tabbyagirl Linux - Newbie 5 08-22-2013 01:46 AM
[SOLVED]Wierd AWK behavior / AWK not reading first line. Involar Linux - Newbie 9 11-28-2012 11:53 AM
running series of awk commands from an awk file oreka18 Programming 3 05-16-2012 02:13 AM
awk error awk: line 2: missing } near end of file boscop Linux - Networking 2 04-08-2012 11:49 AM
[SOLVED] call awk from bash script behaves differently to awk from CLI = missing newlines titanium_geek Programming 4 05-26-2011 10:06 PM


All times are GMT -5. The time now is 05:55 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration