112

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?

1
  • I always like thegeekstuff.com. They cut straight to the examples, as opposed to the usual man page which feels like 90% footnotes. Commented Dec 26, 2015 at 23:41

7 Answers 7

80

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)

RegularExpressions.info

sed tutorial

grep tutorial

info sed, info grep and info awk or info gawk

2
  • @Sundeep: You should have added your own answer instead of "deleting" mine. Commented Jun 28, 2022 at 15:36
  • 1
    Sorry if you feel my edit was out of the line. I've rolled back the changes.
    – Sundeep
    Commented Jun 29, 2022 at 3:19
20

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

12

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.

0
3

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

3

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

2

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.

0
0

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.

6
  • 11
    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
    Commented Sep 25, 2010 at 21:57
  • 1
    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
    Commented Sep 28, 2010 at 14:12
  • 1
    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
    Commented Sep 28, 2010 at 15:30
  • 1
    I use awk quite frequently, both for manipulating text datafiles and to help create complex file manipulation commands in conjunction with "xargs". The equivalent Perl script typically takes longer to write unless the operation is too complex to readily to create via awk.
    – Joel Hoff
    Commented Dec 19, 2010 at 14:07
  • 1
    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. Commented Dec 31, 2011 at 4:22

Not the answer you're looking for? Browse other questions tagged .