Linux Commands: Stream Editor


sed-Linux Command

sed command- Stream Editor
Syntax: sed [options]...

Description: A Stream Editor is used to perform basic transformations on text read from a file or a pipe. The result is sent to standard output. The syntax for the sed command has no output file specification, but results can be saved to a file using output redirection. The editor does not modify the original input.
What distinguishes sed from other editors, such as vi and ed, is its ability to filter text that it gets from a pipeline feed. You do not need to interact with the editor while it is running; that is why sed is sometimes called a batch editor. This feature allows use of editing commands in scripts, greatly easing repetitive editing tasks. When facing replacement of text in a large number of files, sed is a great help.
The sed program can perform text pattern substitutions and deletions using regular expressions, like the ones used with the grep command.
The editing commands are similar to the ones used in the vi editor:


Command

Result

a\

Append text below current line.

c\

Change text in the current line with new text.

d

Delete text.

i\

Insert text above current line.

p

Print text.

r

Read a file.

s

Search and replace text.

w

Write to a file.

Apart from editing commands, you can give options to sed. An overview is in the table below:


Option

Effect

-e SCRIPT

Add the commands in SCRIPT to the set of commands to be run while processing the input.

-f

Add the commands contained in the file SCRIPT-FILE to the set of commands to be run while processing the input.

-n

Silent mode.

-V

Print version information and exit.

The sed info pages contain more information; we only list the most frequently used commands and options here.
Example:

Related:

Other Linux Commands:
alias , break , builtin , cal , case , cat , cd , cfdisk , chgrp , chmod , chown , chroot , cksum , cmp , comm , continue , cp , cron , crontab , csplit , cut , date , dc , dd , declare , df , diff , diff3 , dir , dircolors , dirname , dirs , du , echo , egrep , enable , env , eval , exec , expand , export , expr , factor , false , fdformat , fdisk , fgrep , find , fmt , fold , for , fsck , function , getopts , hash , hashcharacter , head , history , hostname , id , if , import , install , join , kill , less , let , ln , local , locate , logname , logout , lpc , lpr , lprm , ls , m4 , man , mbadblocks , mkdir , mkfifo , mknod , more , mount , mtools , mv , nice , nl , nohup , passwd , paste , period , popd , pr , printf , ps , pushd , pwd , quota , quotacheck , quotactl , ram , rcp , read , readonly , return , rm , rmdir , rsync , Run , sdiff , sed , select , seq , set , shift , shopt , shutdown , sleep , sort , split , su , sum , symlink , sync , tac , tail , tar , tee , Test , time , times , top , touch , tr , traceroute , true , tsort , tty , Type , ulimit , umask , uname , Unexpand , uniq , units , unset , unshar , until , useradd , usermod , users , uuencode , watch , wc , whereis , which , while , who , xargs , yes ,
Live2Support.com :
Product - Benefits - Features - How Does it Works - Pricing - SSL Certificates - Signup - Contactus - Login - Submit Resources