Sed Workshop


Introduction

Sed, Stream EDitor works as a filter in processing the input line by line. The input can be file or STDIN. The output of sed is STDOUT.

Getting Started

Login to SSH secure shell client using the following information:
Syntax

sed <option> 'command' <filename>
    where command = pattern + action ;
If pattern is not given, then the action is applied to all the lines ; otherwise it is applied to the lines matching pattern. Regular expression is used to specify patterns.
Some ways to use sed are as follows:
Examples

  1. Substitute Unix with Linux
    • sed 's/Unix/Linux/' student.txt
  2. Substitute Linus with Unix and 10 with 1
    • sed -e 's/Linux/Unix/' -e 's/10/1/' student.txt
  3. Echo the message "This is AWK workshop. AWK is great." and substitute AWK with SED.
    • echo This is AWK workshop. AWK is great. | sed 's/AWK/SED/'
  4. Echo the message "This is AWK workshop. AWK is great." and substitute AWK with SED globally.
    • echo This is AWK workshop. AWK is great. | sed 's/AWK/SED/g'
  5. Write a sricpt file to substitute David with your name.
    • sed -f sedlist student.txt