Some of these command's almost contain complete programming languages.
From those commands only the basics will be explained. For a more detailed
description, have a closer look at the man pages of each command.

sed (stream editor)

Sed is a non-interactive editor. Instead of altering a file by moving the
cursor on the screen, you use a script of editing instructions to sed, plus the
name of the file to edit. You can also describe sed as a filter. Let's have
a look at some examples:

$sed 's/to_be_replaced/replaced/g' /tmp/dummy

Sed replaces the string 'to_be_replaced' with the string 'replaced' and
reads from the /tmp/dummy file. The result will be sent to stdout (normally
the console) but you can also add '> capture' to the end of the line above so
that sed sends the output to the file 'capture'.

$sed 12, 18d /tmp/dummy

Sed shows all lines except lines 12 to 18. The original file is not altered by this command.

awk (manipulation of datafiles, text retrieval and processing)

Many implementations of the AWK programming language exist (most known interpreters are GNU's
gawk and 'new awk' mawk.) The principle is simple: AWK scans for a pattern, and for every
matching pattern a action will be performed.

Again, I've created a dummy file containing the following lines:

"test123

test

tteesstt"

$awk '/test/ {print}' /tmp/dummy

test123

test

The pattern AWK looks for is 'test' and the action it performs when it found a line in the file
/tmp/dummy with the string 'test' is 'print'.

$awk '/test/ {i=i+1} END {print i}' /tmp/dummy

3

When you're searching for many patterns, you should replace the text between the quotes with '-f
file.awk' so you can put all patterns and actions in 'file.awk'.

grep (print lines matching a search pattern)

We've already seen quite a few grep commands in the previous chapters, that display the lines
matching a pattern. But grep can do more.

$grep "look for this" /var/log/messages -c

12

The string "look for this" has been found 12 times in the file /var/log/messages.

[ok, this example was a fake, the /var/log/messages was tweaked :-)]

wc (counts lines, words and bytes)

In the following example, we see that the output is not what we expected. The dummy file, as used
in this example, contains the following text:
"bash introduction howto test file"

$wc --words --lines --bytes /tmp/dummy

2 5 34 /tmp/dummy

Wc doesn't care about the parameter order. Wc always prints them in a standard order, which is,
as you can see: .