Saturday, 21 March 2020

Sed - stream editor


                                        Sed-Stream Editor

A Stream is data that travels from:
  • One process to another through a pipe.
  • one file to another as a redirect.
  • one device to another.
What Sed do:

Sed Performs text transformations on streams.

Examples:
  • Substitute some text for other text.
  • Remove lines.
  • Append text after given lines.
  • Insert text before certain lines.
Note: Sed is used programmatically, Not interactively.


Let's get hands dirty:

#!/bin/bash
echo "John is the assistant regional manager." > manager.txt

  1. To exit the text @ only terminal level,but not on the actual file.

  • sed 's/assistant/assistant to the' manager.txt

                here s - substution.

      2. Sed is case sensitive by default.

          echo 'my name is naveen' > name.txt

sed '/s/NAVEEN/praveen/' name.txt

output:
my name is naveen ( No change)

To solve above problem use:

sed 's/naveen/praveen/i' name.txt          # here i for eliminating case sensitive in sed statement.

or 
sed 's/naveen/praveen/I' name.txt

    3. To change the global entries in the file using sed.

              sed 's/my wife/my life/g' love.txt


     4.To delete the line with specific key word 

              sed '/This/d' love.txt

here the line starting with This will be deleted automaticallay. and result will obtained in the actual file.




9C9D6D00AB6300- Registration code





No comments:

Post a Comment