Sed in Linux

sed is stream   editor, which means that you can find and replace any strings or multiple strings using sed command. It is just like similar as vi find and replace  command . But sed is used to execute that multiple find and replace  commands at once using script.

Using command on terminal.

sed -i  's/john/JOHN/g'  report.tex.

To replace multiple strings

sed -e ‘s/john/JOHN/g’  -e  ‘s/mariya/MARIYA/g’  report.tex.

Following command will show output on terminal

 sed -f replace.sed  report.tex

Script to replace multiple strings.

To do this, create two files. one with .sed extension and second with .sh. Because its a bash script file. And third file will be your source file , on which you want to apply script.

 sed -f replace.sed < report.tex > correctreport.tex

Output: after running

\author{Manpreet Dhiman}
\chapter{student record}

  \item JOHN
  \item MARIYA
  \item sid
  \item ALIYA
  \item CHERRY


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s