Learn What is the Sed Command in Linux

04 May 2023 Balmiki Mandal 0 Linux

Sed Command in Linux

Sed is a stream editor, a powerful command-line tool that enables you to edit text files in Linux. It works by making changes to one or more files and writing the changes to standard output (by default). Sed can be used to delete lines, search and replace, insert lines, and perform other text processing operations.

Sed is widely used for sorting, filtering, formatting and transforming data, as well as for automating specific tasks. It can be used in combination with other commands to create powerful scripts for various purposes, from system administration to website development and more.

Syntax of Sed Command

The basic syntax of sed command is −

sed [options] 'command' file(s)

Basic sed Command Examples

Let's take a look at some basic sed commands and their examples:

  • Delete Lines Containing Specific Text - sed '/text/d' filename
  • Search and Replace Text - sed 's/old/new/g' filename
  • Insert a Line After Matching Text - sed '/text/a\new line' filename
  • Insert a Line Before Matching Text - sed '/text/i\new line' filename
  • Substitute Whole Line With New Text - sed 's/.*/new line/' filename
  • Delete Nth Line In a File - sed 'Nd' filename

In addition to these basic commands, there are several other options and commands available with the sed command. To learn more about the sed command, you can refer to the man page or search the web for further information.

BY: Balmiki Mandal

Related Blogs

Post Comments.

Login to Post a Comment

No comments yet, Be the first to comment.