Understanding & Using sed Command in Linux

Опубликовано: 30 Сентябрь 2024
на канале: Decode ITES
825
6

#DecodeITeS

SED command in Linux stands for stream editor and it can perform lots of functions on a file like, searching, find and replace, insertion or deletion.
Though the most common use of SED command in Linux is for a substitution or for find and replace.
By using SED we can edit files even without opening them, which is a much quicker way to find and replace something in the file, than first opening that file in VI/VIM Editor and then changing it.

SED is a powerful text stream editor in Linux. It Can perform insertion, deletion, search and replace(substitution).
SED command in unix supports regular expression(s) which allows it perform complex pattern matching.

Syntax:
sed OPTIONS... [SCRIPT] [INPUTFILE...]

Standard sed command examples:
Replacing or substituting string
Replacing the nth occurrence of a pattern in a line
Replacing all the occurrence of the pattern in a line
Replacing from nth occurrence to all occurrences in a line
Replacing string on a specific line number
Duplicating the replaced line with /p flag
Printing only the replaced lines
Replacing string on a range of lines