Linux sed command

sed stands for stream editor. Linux sed command is used to search a word in the file and replace it with the word required to be in the output.

Note: It will only modify the output, but there will be no change in the original file.

Examples:

Create a file:

[root@localhost k2admin]# cat > k2file.txt
Welcome to k2schools
Welcome to k2schools again and again
Welcome to k2schools
Linux is open source operating system
Linux is open source operating system

Change the text in output:

[root@localhost k2admin]# sed ‘s/k2schools/k2schoolsworld/g’ k2file.txt
Welcome to k2schoolsworld
Welcome to k2schoolsworld again and again
Welcome to k2schoolsworld
Linux is open source operating system
Linux is open source operating system

Content of actual file is remains same.

[root@localhost k2admin]# cat k2file.txt
Welcome to k2schools
Welcome to k2schools again and again
Welcome to k2schools
Linux is open source operating system
Linux is open source operating system

Powered by k2schools
Skip to toolbar