Is there a basic tutorial for grep, awk and sed?

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?

Asked By: Macha


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 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.

Answered By: fschmitt

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 (alt link)

sed tutorial

grep tutorial

info sed, info grep and info awk or info gawk

Answered By: Dennis Williamson

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

Answered By: user591

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.

Answered By: user1606

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

Answered By: ixtmixilix

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”.

Answered By: HandyGandy

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.

Answered By: Daniel Goldman
Categories: Answers Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.