sed Command: Tutorial & Examples
Perform text manipulation and substitution tasks
The sed
command is a utility that is used to perform text manipulation and substitution tasks on Linux systems. It is a powerful tool that is often used to edit text files or
command output in place, or to filter and transform text in a pipeline.
sed
works by reading input line by line, applying a set of rules or commands to each line, and then printing the result. The rules or commands are specified using a simple
programming language that is similar to regular expressions.
Here is a simple example of using sed
to replace all occurrences of the word "old" with the word "new" in a file:
sed 's/old/new/g' file.txt
You can use the -i
flag to edit the file in place, rather than printing the modified file to the terminal:
sed -i 's/old/new/g' file.txt
This will replace all occurrences of the word "old" with the word "new" in the file and save the changes to the file.