DevOps/Cloud By GK
  • DevOps/Cloud Introduction
  • 🚩AWS
    • Create AWS Account
    • Launch EC2 Instance
  • 🚩Linux
    • User Managment
      • Adding the User to Sudo group
      • visudo
    • Directory / File Management
      • Vi
      • Changing Permissions (chmod)
      • Filtering IO/File
    • Memory Management
    • Process Management
    • Network Management
    • Service Management
    • Environmental Variables
      • $PATH
    • Utilities
    • SHELL PROGRAMMING
      • Hello World
      • Variables
      • Command Line arguments
      • Conditional Statements
      • Array
      • Loops
      • Functions
      • AWK
      • sed
      • Example Useful Scripts
      • Basic -> Advanced
  • 🚩git
    • Introduction
    • Creating GitHub Account
    • Installation
      • Git Bash In Windows
      • Git In VS Code
      • Git In Eclipse
      • Git CLI in Linux
  • Creating Git Remote Repository
  • Git Commands L -> R
  • Git Commands L <- R
  • Git Branch Commands
  • Using SSH (Password Less)
  • 🚩maven
    • Introduction
    • Installation
    • POM.xml
    • Goals
  • 🚩SonarQube
    • Introduction
    • Sonar Cloud
    • Creating Project In SonarCloud
    • Installing Sonar-Scanner
    • Triggering Scan
  • 🚩Nexus
    • Introduction
    • Installation of Nexus
    • Creating Repository
    • Uploading Artifacts to Repository
  • 🚩Jenkins
    • Introduction
    • Installation of Jenkins
    • First Job In Jenkins
    • Git + Jenkins
      • WebHook
    • Maven + Jenkins
    • Sonar-Scanner + Jenkins
    • Nexus + Jenkins
Powered by GitBook
On this page
  1. Linux
  2. SHELL PROGRAMMING

sed

The sed command (short for "stream editor") is a powerful utility for text manipulation in Linux and Unix-like operating systems. It operates on a line-by-line basis, reading input and applying specified operations or transformations to the text. sed commands can be provided directly on the command line or stored in a script file for more complex operations.

Here are a few examples that illustrate the usage of sed:

  1. Find and Replace Text: The s command in sed is used to substitute text. For example, let's say we have a file called file.txt with the following content:

Hello, World!

We can use sed to replace "Hello" with "Hi" in the file:

sed 's/Hello/Hi/' file.txt

The output will be:

Hi, World!

In this example, the s/Hello/Hi/ command tells sed to substitute the first occurrence of "Hello" with "Hi" in each line of the input.

  1. Delete Lines: The d command in sed is used to delete lines. For example, let's consider the same file.txt as above, and we want to delete the line containing "Hello":

sed '/Hello/d' file.txt

The output will be empty, as the line containing "Hello" has been deleted.

  1. File Content Appending: The sed command can be used to append text to the end of each line in a file. For example, let's say we have a file called data.txt with the following content:

apple
banana
orange

We can use sed to append "(fruit)" to the end of each line:

sed 's/$/ (fruit)/' data.txt

The output will be:

apple (fruit)
banana (fruit)
orange (fruit)

In this example, the s/$/ (fruit)/ command appends " (fruit)" to the end of each line. The $ represents the end of the line.

These are just a few basic examples of using the sed command. sed provides a wide range of operations, including searching and replacing patterns, inserting and deleting lines, conditional operations, and more. Its capabilities can be further explored by referring to the documentation and learning about its various commands, options, and syntax.

PreviousAWKNextExample Useful Scripts

Last updated 2 years ago

🚩