Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I've been a Linux user for a while, and I've a pretty decent understanding of most the common command line utilities. However, ones that come up and up again in relation to programming are grep, awk, and sed.

About the only thing I've used grep for is piping stuff into it to find files in log files, the output of ps etc. I haven't used awk or sed at all. Are there any good tutorials for these utilities?

share|improve this question

closed as too broad by Braiam, slm Aug 23 '14 at 4:51

There are either too many possible answers, or good answers would be too long for this format. Please add details to narrow the answer set or to isolate an issue that can be answered in a few paragraphs.If this question can be reworded to fit the rules in the help center, please edit the question.

You betcha! :) – gvkv Sep 26 '10 at 5:23
I've always put off learning regex because I tell myself that I'll one day learn it by reading Kleene's original papers on logic that invented the concept before it became widely used in computers. – ixtmixilix Dec 28 '10 at 17:13
I agree with gvkv: if you need to learn these, you might as well learn Perl, it does what grep, sed and awk do (and in almost the same way) and a lot more on top. – reinierpost Nov 17 '15 at 9:19
I always like thegeekstuff.com. They cut straight to the examples, as opposed to the usual man page which feels like 90% footnotes. – isomorphismes Dec 26 '15 at 23:41
up vote 48 down vote accepted

AWK is particularly well suited for tabular data and has a lower learning curve than some alternatives.

AWK: A Tutorial and Introduction

An AWK Primer


sed tutorial

grep tutorial

info sed, info grep and info awk or info gawk

share|improve this answer
I replaced the dead link. – Dennis Williamson Sep 15 '14 at 19:24

The O'Reilly sed and awk book is great for er sed and awk.

share|improve this answer

I wrote a book on sedDefinitive Guide to sed—that includes a tutorial. It fully covers sed, as well as related commands like grep, tr, head and tail. Also fully covers regular expressions much better than I've seen elsewhere.

I agree with others that solid understanding regular expressions well is very important. I also agree that sed is best used for simpler tasks, more complex scripts quickly get obscure.

I disagree that awk is obsolete, just the opposite. It's like many unix things (e.g., vi), there is a learning curve, but it's worth it.

I disagree with the suggestion to use awk in place of grep. Does not make sense in my experience. grep is so great and simple.

share|improve this answer
I second the grep thing - you dont take the tractor on the freeway if you can help it. And its a pretty good book, too - thank you. – mikeserv Aug 23 '14 at 4:44

The Regular Expressions Cookbook published by O'Rielly would be enough to get you anywhere in any language that uses them.

share|improve this answer

If you are to learn one out of these 3( grep , sed and awk ) , you can just learn awk/gawk.. awk can do grep and sed's functions, ie using regex to search/replace text, plus much more because its also a programming language. If you learn the inside outs of gawk/awk, you won't need to use grep/sed/wc/cut etc. Just one tool does it.

share|improve this answer
oh, btw, we don't even need awk, you can just use g++ -x c++ - -o /tmp/prog && /tmp/prog and type your commands away. One tool to rule them all! :-) – Lie Ryan Sep 28 '10 at 9:10
who needs a compiler when you can just write the binary straight into a file? cat will do, or ed if you're feeling lazy. – cas Sep 29 '11 at 4:54

The authors of the book are Kernigan and Pike the title is something like "The Unix Programming Environment".

The book that I actually learned from was called "An Introduction to Berkely Unix".

share|improve this answer

In my opinion, awk is more or less obsolete (however, others will strongly argue this opinion), most people I know nowadays instead use some script language like perl or today often python for advanced text manipulation. sed is great for simpler text manipulation tasks, I use it all the time. I learned it mainly by looking at sed one-liners like those at http://sed.sourceforge.net/sed1line.txt. Regarding grep: Well you basically want to get a solid understanding of regular expressions (also needed for sed). I here just used the texinfo manuals.

share|improve this answer
awk is still very useful for manipulating data piped from other commands. For simple command line usage, I wouldn't consider it obsolete just yet. – MaQleod Sep 25 '10 at 21:57
Also it should be available on many systems because of POSIX. – echox Sep 27 '10 at 13:04
Most 'advanced AWK' is probably better done with perl or python or whatever, but the simple stuff is nice to do with just awk. – user455 Sep 28 '10 at 14:12
Awk is still useful to know to understand various answers you might find online when trying to solve a problem. You will often find examples online that use awk statements like awk '{print $3}'. – Steven D Sep 28 '10 at 15:30
At work, and and home, I use awk more often then sed. Nothing can beat awk at fixed tabular data, like dpkg -l output. I wouldn't do anything remotely complicated in it, but I'd be short a tool without awk. I can't say the same for more general programming languages, as much as I like some of them. – TechZilla Dec 31 '11 at 4:22

Not the answer you're looking for? Browse other questions tagged or ask your own question.