125 words
1 minutes
sed command is AMAZING
sed
, which stands for stream editor, is a powerful text processing tool used in Linux and other Unix-like operating systems. It performs text transformations on an input stream (a file or input from a pipeline). Here are some common uses of sed
:
Substitution
The most common operation is to replace text in a file. For example:
sed 's/original/replacement/' filename
This command will replace the first occurrence of original
with replacement
in each line of the file.
Global Substitution
If you want to replace all occurrences in a line, you use the g flag:
sed 's/original/replacement/g' filename
This replaces all occurrences of original
with replacement
in each line.
In-place Editing
By default, sed
outputs to the standard output. To save changes back to the file, use the -i
option:
sed -i 's/original/replacement/g' filename
This modifies the file in-place.