Live data from Hacker News

Ask HN: Should I learn Awk or Perl? Or is that a bad question?

news.ycombinator.com

1–10 of 37 posts

Ask HN: Should I learn Awk or Perl? Or is that a bad question?

#1
I find myself being totally lost on the command line when I need to do more complex stuff - a series of pipes between greps and cuts and the works. Recently, I finally took some time to try to learn some awk and it was life changing. I’ve been doing some awk puzzles, but it occurred to me that if I’ll be deliberately spending time learning a command line text processing tool, I may as well go the extra mile and learn perl, which I’ve heard is far more expressive than gawk.

I’m also noticing a lack of literature on Perl on the command line, I.e “perl -nae ”.

Is awk just better for this use case?

Re: Ask HN: Should I learn Awk or Perl? Or is that a bad question?

#2
Awk for sure! The pdf for the original awk book is somewhere around the web, i learned awk from that and it’s mostly still good. I heard they made a new edition some time ago? Really worth reading!

For perl… not sure. I learned a bit of perl in high school and never had a chance to use it, even at work where i occasionally see it being used from other people.

Re: Ask HN: Should I learn Awk or Perl? Or is that a bad question?

#4
Maybe not so much a question of 'better' but perl is definitely bigger and multiheaded and does many, many more things (perl scientists were so preoccupied with whether or not they could, they didn't stop to think if they should). So you'll spend a lot more time (compared to awk) orienting yourself, beside the learning of the thing you want to know about. That could be a fun extra hobby or a waste of time, depending on your goals and inclinations.

Re: Ask HN: Should I learn Awk or Perl? Or is that a bad question?

#5
If you're looking at learning Perl then you'll find the https://perldoc.perl.org/ site very useful (you'll probably also have its content available on the command line via the perldoc command).

If you want more information about running Perl on the command line then start with https://perldoc.perl.org/perlrun (or `perldoc perlrun` in your shell)

Re: Ask HN: Should I learn Awk or Perl? Or is that a bad question?

#9
How much time do you want to invest ?

Perl is more powerful but learning and remembering all (or a sufficiently more powerful superset of awk's capabilities) of it is going to take time. The peculiarities of its syntax is certainly not a small set.

All of awk on the other hand needs about 2 hours, if you have done some programming before.

Re: Ask HN: Should I learn Awk or Perl? Or is that a bad question?

#10
>> I’m also noticing a lack of literature on Perl on the command line, I.e “perl -nae ”.

Searching for 'perl one liners' and the related term 'perl golf' gives many articles and books:

https://www.perl.com/article/perl-one-liners-part-1/

https://www.perl.com/article/perl-one-liners-part-2/

https://catonmat.net/perl-one-liners-explained-part-one

https://catonmat.net/perl-one-liners-explained-part-two

https://catonmat.net/perl-one-liners-explained-part-three

https://catonmat.net/perl-one-liners-explained-part-four

https://catonmat.net/perl-one-liners-explained-part-five

https://catonmat.net/perl-one-liners-explained-part-six

https://catonmat.net/perl-one-liners-explained-part-seven

http://novosial.org/perl/one-liner/

https://www.oreilly.com/library/view/perl-one-liners/9781457...

Post reply on HN