Stream Editor - Basic Syntax


Some of the basic commands that support SED and their command-line syntax are as follows.

 \\This allows to specify the commands in-line and they are enclosed within single quotes.  
sed [-n] [-e] 'command(s)' files  

-------------------------------
-------------------------------

\\This allows to specify a script file that contains SED commands
sed [-n] -f scriptfile files


Note:we can use both forms together multiple times.

Examples

Let us create a text file lfc.txt that include the details of some famous books.

$ cat lfc.txt 

-------------------
-------------------

Output :- 

Walden, Henry David Thoreau
The Discovery Of India, Jawaharlal Nehru
The Algebra of Infinite Justice, Arundhati Roy
Bookless in Baghdad, Shashi Tharoor
Adventures of Sherlock Holmes, Sir Arthur Conan Doyle



As we all know that SED provides delete command to delete some lines. Now we will remove the first and the fourth line from the text file.

$ sed -e '1d' -e '4d' lfc.txt 

-------------------
-------------------

Output :- 

The Discovery Of India, Jawaharlal Nehru
The Algebra of Infinite Justice, Arundhati Roy
Adventures of Sherlock Holmes, Sir Arthur Conan Doyle







Visit :


Discussion


* You must be logged in to add comment.