Saturday, January 9, 2021

Linux Series - SED Utility/Package - 2. Input Methods

As mentioned in this article, sed reads the input from two different ways.

1. via file

   Example: Let us create a file called test.txt and it contains the text called Linux.


This file is an input to sed command. Let us see how sed process this input file.
Run the command "sed 's/Linux/Windows/' test.txt". 

Basically, option "s" passes in sed command when you want to substitute the text with another text.  "s" means substitution
sed reads the input of test.txt file and it replaces the word "Linux" with "Windows" and displayed in the terminal.  However, this above command will not replace "Linux" with "Windows" in actual file (test.txt).  Let us confirm it.

2. via pipe
Hope you know how pipe works in linux. If not, the below picture represents how pipe works.
Output of command1 will be the input for command2.
Example: Let us use pipe in sed command to understand how it works. For this, we are again using the same test.txt file.

When you execute "cat test.txt" command will return the text "Linux" which is the input to sed command where sed replaces "Linux" with "Windows".

Hope you understand how sed reads the input and process the command😀.





No comments:

Post a Comment

Linux Series - SED Utility/Package - 4. Deleting Lines

Let’s explore sed’s explicit delete command, which you specify by using the option 'd'. Again, we are using the sample file named &#...