Linux Shell Scripting Tutorial (LSST) v1.05r3
Prev
Chapter 5: Essential Utilities for Power User
Next

sed utility - Editing file without using editor

For this part of tutorial create data file as follows

teaormilk

India's milk is good.
tea Red-Lable is good.
tea is better than the coffee.

After creating file give command
$ sed '/tea/s//milk/g' teaormilk  > /tmp/result.tmp.$$
$ cat /tmp/result.tmp.$$
India's milk is good.
milk Red-Lable is good.
milk is better than the coffee.

sed utility is used to find every occurrence of tea and replace it with word milk. sed - Steam line editor which uses 'ex' editors command for editing text files without starting ex. (Cool!, isn't it? no use of text editor to edit anything!!!)

/tea/Find tea word or select all lines having the word tea
s//milk/Replace (substitute) the word milk for the tea.
gMake the changes globally.

Syntax:
sed {expression} {file}

Use of sed utility: sed is used to edit (text transformation) on given stream i.e a file or may be input from a pipeline.


Prev
Home
Next
Data manipulation using awk utility
Up
Removing duplicate lines using uniq utility