* Sed command stand for Stream Editor is very powerful utility offered by Linux systems.
* It is mainly used for text substitution , find & replace but it can also perform other text manipulations like insertion, deletion,
search etc. With SED, we can edit complete files without actually having to open it.
* By using SED you can edit files even without opening it, which is much quicker way to find and replace something in file,
than first opening that file in VI Editor and then changing it. SED is a powerful text stream editor.
With sed you can do all of the following:
Select text
Substitute text
Add lines to text
Delete lines from text
Modify (or preserve) an original file
Example:
Deleting a line using sed command
To delete a line with sed from a file, use the following command,
[linuxtechi@localhost ~]$ sed Nd testfile.txt
where ‘N’ is the line number & option ‘d’ will delete the mentioned line number. To delete the last line of the file, use
Adding Blank lines/spaces
To add a blank line we will use option ‘G’,
[linuxtechi@localhost ~]$ sed G testfile.txt
Deleting a range of lines
To delete a range of lines from the file, run
[linuxtechi@localhost ~]$ sed '29,34d' testfile.txt
This will delete lines 29 to 34 from testfile.txt file.
What is SED command?
Modify (or preserve) an original file
Example:
[linuxtechi@localhost ~]$ sed Nd testfile.txt where ‘N’ is the line number & option ‘d’ will delete the mentioned line number. To delete the last line of the file, use
[linuxtechi@localhost ~]$ sed G testfile.txt
[linuxtechi@localhost ~]$ sed '29,34d' testfile.txt
This will delete lines 29 to 34 from testfile.txt file.