Linux Shell Scripting Tutorial (LSST) v1.05r3
Chapter 7: awk Revisited

sed - Quick Introduction

SED is a stream editor. A stream editor is used to perform basic text transformations on an input stream (a file or input from a pipeline). SED works by making only one pass over the input(s), and is consequently more efficient. But it is SED's ability to filter text in a pipeline which particularly distinguishes it from other types of editors.

Before getting started with tutorial you must know basic expression which is covered in our Learning expressions with ex tutorial. For this part of tutorial create demofile1. After creating the file type following sed command at shell prompt:

$ sed 's/Linux/UNIX(system v)/' demofile1
Hello World.
This is vivek from Poona.
I love linux.
linux is linux

Above sed command can be explained as follows:

sed  Start the sed command
's/Linux/UNIX(system v)/'  Use substitute command to replace Linux with UNIX(system v). General syntax of substitute is s/pattern/pattern-to-substitute/'
demofile1Read the data from demofile1

General Syntax of sed
sed -option 'general expression' [data-file]
sed -option sed-script-file [data-file]

Option can be:

-eRead the different sed command from command line.
$ sed  -e  'sed-commands'    data-file-name
$ sed  -e   's/Linux/UNIX(system v)/'    demofile1
-fRead the sed command from sed script file.
$sed   -f   sed-script-file    data-file-name
$ sed  -f  chgdb.sed    friends.tdb
-nSuppress the output of sed command. When -n is used you must use p command of print flag.$ sed -n  '/^\*..$/p'   demofile2

awk miscellaneous
Redirecting the output of sed command