---
created_at: '2017-06-27T16:51:59.000Z'
title: Awk vs. Perl (2009)
url: http://aplawrence.com/Unixart/awk-vs.perl.html
author: type0
points: 46
story_text: 
comment_text: 
num_comments: 71
story_id: 
story_title: 
story_url: 
parent_id: 
created_at_i: 1498582319
_tags:
- story
- author_type0
- story_14647022
objectID: '14647022'

---
[Source](http://aplawrence.com/Unixart/awk-vs.perl.html "Permalink to Awk vs. Perl")

# Awk vs. Perl

[ ![][1]][2]

# 

* [Home][3]
* [Linux][4]
* [Contact][5]
* [Site Map][6]
* [Home][3]
* [Linux][4]
* [Contact][5]
* [Site Map][6]

# [Awk vs. Perl][7]

At any Linux/Unix forum a large number of posts have to do with sed and awk - how do I do this, how do I do that?

I can see using sed. It's quick, it's simple (unless we are doing something complicated) and easy to learn. On the other hand, we have "awk", which is nasty and error prone even in its most basic invocations.

_That's just my opinion, of course._

Sure, I used to use awk. When I used it, you weren't likely to find Perl on most Unix systems, so for a lot of text mangling, awk was at least easier than writing in C or anything else. It did the job, and you'd get used to its quirks.

As Perl became ubiquitous, I thought of awk like something sticky you'd find under your car seat. Whatever use that thing may have had in the past, it's heading for the trash now. Why on earth would I suffer with awk's limitations and difficult synatx when I have Perl?

For me, awk synatx always seemed, well, awkward. Perl immediately made sense to me. In a way, that's scary, because it could mean that my mind works like Larry Wall's mind, and if that wouldn't cause you to check in with a psychiatrist, I don't know what would. 

I'm hardly alone in that opinion. Many of those forum questions end up being answered by a Perl script. To me, the Perl solution always seems easier to read and understand (that may just be my screwy mind, again).

Yet the forum questions persist. Some of it is homework: you can often tell when the petitioner includes such damning information as "I have to use awk. Can't use Perl" or forgets to delete instructions like "Show your work" when cutting and pasting. But it's not all homework: apparently a large number of people still use awk.

I went looking for why and found this: [AWK Programming ][8]. Some of the arguments made there in favor of awk include:

* awk is simpler (especially important if deciding which to learn first) 
* awk syntax is far more regular (another advantage for the beginner, even without considering syntax-highlighting editors) 
* you may already know awk well enough for the task at hand 
* you may have only awk installed 
* awk can be smaller, thus much quicker to execute for small programs 
* awk variables don't have `$' in front of them :-) 
* clear perl code is better than unclear awk code; but NOTHING comes close to unclear perl code
  

I'm not entirely in agreement - I don't think awk is "simpler" or has better syntax, but I can see that you could argue that. But even that page admits that "Generally Perl might be better for really complex tasks". I'd argue that awk is clumsy at complex tasks, but I definitely have to agree with that last comment about "unclear" code.

Probably many of the readers here used awk before discovering Perl. Did Perl win you over or do you still find yourself typing "awk" frequently? If you haven't used Perl, is it the learning curve? Or just that you can do whatever you need with the tools you already have?

  
  

Got something to add? Send me [email][5].

  
  
  
  
[(OLDER) ][9] <\- More Stuff -> [(NEWER)   ][10] [(NEWEST)   ][3]  
  
[Printer Friendly Version][11]  
  

[Home][3]

->

[Unix Articles][12]

-> Awk vs. Perl 

  

[8 comments][13]

  
  
[Increase ad revenue 50-250% with Ezoic][14] ![][15]

  
Inexpensive and informative Apple related e-books:   
  
[Take Control of the Mac Command Line with Terminal, Second Edition][16]   
  
[Take Control of Security for Mac Users][17]   
  
[Take Control of Upgrading to El Capitan][18]   
  
[Take control of Apple TV, Second Edition][19]   
  
[Take Control of Preview][20]   
  
  

  
  
  

More Articles by [Anthony Lawrence][21]   
  
[Find me on Google+][22]  
  
© 2012-08-15 Anthony Lawrence 

  

  
  
  
  
  
_Mon Nov 9 17:01:23 2009: _ 7505   AndrewSmallshaw   
  
![gravatar ][23]   
I've always thought the greatest strength of awk is its convenience - it will be installed on a Unix system and it has enough in common with C for there to be at least some carry-over. Too often tool selection is not about niceties such as how elegant the code is - you have some kind of task to sort out and it needs doing NOW. Learning a new tool is often not for future reference, but to carry out an immediate task.   
  
The best way to learn a new tool is to spending a couple of days (or even an afternoon) playing around with it when no immediate deliverables are expected. If that is not the case known tools (or something that looks like it can be picked up quickly) are more attractive, even when there may be clearly more appropriate alternatives. That's why I first picked up awk, and I think I was right - my first (100 line) script took around four hours - a long time, but comparatively short for learning a new tool. What I couldn't justify for that job was going off and spending a couple of days learning perl. It doesn't matter how suitable it would be, or how it pays off over the long run - sometimes the immediate need is more pressing.   
  
Of course, once you know one tool for a job it becomes more difficult to justify learning a second tool for the same class of problems. You might like to learn that alternative but face it - there are too many things out there and so new learning generally has to be prioritised according what is most needed.   
  
  
  
_Mon Nov 9 17:22:38 2009: _ 7507   jtimberman   
  
![gravatar ][24]   
I learned awk and sed at first, and I still use them for two specific reasons:   
  
sed 's/something/somethingelse/'   
awk '{print $2}'   
  
I used awk for some more complex functionality due to a work project requirement. I tried Perl, and used it for a few projects, but it just never clicked with me, especially all the quirky variable sigils and their usage.   
  
Fast forward to now, I use Ruby for everything. It makes more sense to me than Perl ever did.   
  
  
  
_Mon Nov 9 21:43:20 2009: _ 7508   TonyLawrence   
  
![gravatar ][25]   
That's so interesting. For me, Ruby is confusing - Perl makes sense. I was using awk regularly but when I leaned Perl, I dropped awk like worn out sneakers.   
  
Odd how our minds can work so differently.   
  
  
  
_Sun Aug 8 19:50:04 2010: _ 8879   aMoLk   
  
![gravatar ][23]   
  
  
I have been using awk and sed for few years managing unix systems. I mostly write scripts in korn shell, and while my scripts may range from small to upto a few hundred lines, the requirement of awk is usually pretty limited to 5-10 lines max. So, for me awk works since it is present on 100% of the systems that I work on, while perl may not be installed in some cases. So, awk remains the choice for me. Although, I've been trying to learn perl lately, so that I can use both tools on a as needed basis.   
My inclination towards perl is simply because I can use it on windows as well.   
  
  
  
_Sun Aug 8 19:57:57 2010: _ 8880   TonyLawrence   
  
![gravatar ][25]   
  
  
Yes, that is a big advantage.   
  
  
  
_Wed Feb 29 23:38:28 2012: _ 10676   Polaris   
  
![gravatar ][23]   
  
  
awk isubiquitous. it feels much more shell like like than perl. Also, it's rather C like. These are my opinions, butthey make awk seem very friendly to me.   
  
I like using awk to do "super-scripting" I define these as tasks that are a bit ambitious for bash but not big enough for a major project. Of course, the downside is that now I use awk for bigger things than it should be...   
  
also, i like awk better the sed for "one off" filtering. I think it's a bit saner to the reader during the tweaking process.   
  
I wish I knew perl better, but so far I've only dabbled. I do really like awk, though   
  
  
  
_Wed Aug 15 21:12:48 2012: _ 11237   Michael   
  
![gravatar ][26]   
  
  
awk is the first choice in two cases:   
1\.   
awk 'condition {print $2}'   
where condition can be null or /EREsearch/ or $1=="string" or $1~/EREsearch/ or $1>45 or ...   
2\.   
with associative array. Example:   
awk 's[$0]++==0'   
is short for   
awk 's[$0]++==0 {print}'   
Effectively it omits duplicate lines without changing the order.   
Compare with an expensive sort | uniq or sort -u !   
The associative arrays in Perl are more cryptic.   
  
  
  
  
  
  
_Wed Aug 15 21:37:55 2012: _ 11238   TonyLawrence   
  
![gravatar ][25]   
  
  
Cryptic? Different stores, I guess. I find awk cryptic - Perl makes sense to me!   
  
\------------------------  

![Kerio Samepage][27]   
  

* * *

  
[Printer Friendly Version][11]  
  

[Site map][28]     |      [Disclaimer][29]  
  
[Awk vs. Perl  Copyright © November 2009 Tony Lawrence ][30]   
  

Have you tried [Searching this site?][31]

Support Rates

This is a Unix/Linux resource website. It contains technical articles about Unix, Linux and general computing related subjects, opinion, news, help files, how-to's, tutorials and more. 

[Contact us][5]

  
[Printer Friendly Version][11]  
  

* [Privacy Policy][32]

Search website

| ----- |
| 

|   | 

 |   | 

#### SHARE

[Tweet][33]

#### ADDITIONAL INFO

  
  

  
  

UNIX is simple. It just takes a genius to understand its simplicity. (Dennis Ritchie) 

  
  
  

[Linux posts][4]  
  

[Troubleshooting posts][34]  
  

  
**This post tagged: **  

  

[**AWK][35]**  
  

[**Linux][36]**  
  

[**Perl][37]**  
  

[**Scripting][38]**  
  

[**Shell][39]**  
  

  
  

[Unix/Linux Consultants][40]  
  
[Skills Tests][41]  
  
[Unix/Linux Book Reviews][42]  
  
[My Unix/Linux Troubleshooting Book][43]  
  
[This site runs on Linode][44]

  
  
  
  
  

![][45]

![Quantcast][46]

[1]: //cdn.aplawrence.com/utilcave_com/middleton/img.webp?dirname=aplawrence_com&img=/logo/aplawrence_com&ecb=173-5
[2]: http://aplawrence.com
[3]: http://aplawrence.com/index.html
[4]: http://aplawrence.com/cgi-bin/indexget.pl?arg=Linux
[5]: http://aplawrence.com/info.html
[6]: http://aplawrence.com/site%20map.html
[7]: http://aplawrence.com/Unixart/awk-vs.perl.html "Sure, I used to use awk.   When I used it, you weren't likely to find Perl onmost Unix systems, so for a lot of text mangling, awk was at least easier than writing in C or anything else.  It did the job, and you'd get used to its quirks."
[8]: http://www.softpanorama.org/Tools/awk.shtml
[9]: http://aplawrence.com/Linux/hylafax.html
[10]: http://aplawrence.com/Unixart/sort-vs-uniq.html
[11]: http://aplawrence.com/cgi-bin/printer.pl?arg=/Unixart/awk-vs.perl.html
[12]: http://aplawrence.com/Unixart
[13]: http://aplawrence.com#commentshere
[14]: http://www.ezoic.com/?tap_a=6413-3dac80&tap_s=15010-a5bbce
[15]: https://static.tapfiliate.com/pix.gif?a=6413-3dac80&s=15010-a5bbce
[16]: https://www.takecontrolbooks.com/command-line?aff=AFL1361639390
[17]: https://www.takecontrolbooks.com/mac-security?aff=AFL1361639390
[18]: https://www.takecontrolbooks.com/el-capitan-upgrading?aff=AFL1361639390
[19]: https://www.takecontrolbooks.com/apple-tv?aff=AFL1361639390
[20]: https://www.takecontrolbooks.com/preview?aff=AFL1361639390
[21]: http://aplawrence.com/cgi-bin/getauthart.pl?arg=Anthony%20Lawrence
[22]: https://plus.google.com/113844487094333569134?rel=author
[23]: http://www.gravatar.com/avatar.php?gravatar_id=d41d8cd98f00b204e9800998ecf8427e&s=40
[24]: http://www.gravatar.com/avatar.php?gravatar_id=7cc36436cd8187a29be6137c3f0dd3e7&s=40
[25]: http://www.gravatar.com/avatar.php?gravatar_id=2e6a807aad6127e18b07e96ad8caedef&s=40
[26]: http://www.gravatar.com/avatar.php?gravatar_id=8796ac8fc927a48c84debc0aba519400&s=40
[27]: http://cdn-0.aplawrence.com/images/samepage250C.png
[28]: http://aplawrence.com/sitemap.html
[29]: http://aplawrence.com/disclaimer.html
[30]: http://aplawrence.com/cgi-bin/freprint.pl?arg=/Unixart/awk-vs.perl.html
[31]: http://aplawrence.com/search.html
[32]: http://aplawrence.com/privacy.html
[33]: https://twitter.com/share
[34]: http://aplawrence.com/cgi-bin/indexget.pl?arg=Troubleshooting
[35]: http://aplawrence.com/cgi-bin/indexget.pl?arg=AWK "More articles about AWK"
[36]: http://aplawrence.com/cgi-bin/indexget.pl?arg=Linux "More articles about Linux"
[37]: http://aplawrence.com/cgi-bin/indexget.pl?arg=Perl "More articles about Perl"
[38]: http://aplawrence.com/cgi-bin/indexget.pl?arg=Scripting "More articles about Scripting"
[39]: http://aplawrence.com/cgi-bin/indexget.pl?arg=Shell "More articles about character based shells and administration"
[40]: http://aplawrence.com/consultants.html
[41]: http://aplawrence.com/Tests
[42]: http://aplawrence.com/cgi-bin/indexget.pl?arg=Books
[43]: http://www.amazon.com/dp/B004Q3RK8C
[44]: http://www.linode.com/?r=e045b324074009e0f6c5b8c3454ea2774930f3dc
[45]: https://sb.scorecardresearch.com/p?c1=2&c2=20015427&cv=2.0&cj=1
[46]: //pixel.quantserve.com/pixel/p-31iz6hfFutd16.gif?labels=Domain.aplawrence_com,DomainId.4525

