Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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
    
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
add comment

6 Answers

up vote 38 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

RegularExpressions.info

sed tutorial (with links to more)

grep tutorial

info sed, info grep and info awk or info gawk

share|improve this answer
1  
"sed tutorial" link no longer works. It gives 403 forbidden response. –  Muhd Jan 31 at 0:28
add comment

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

share|improve this answer
add comment

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
add comment

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
6  
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
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 Sep 28 '10 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 Sep 28 '10 at 15:30
    
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 Dec 19 '10 at 14:07
show 1 more comment

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
add comment

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
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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