

In this example, we will delete the third line from the ‘sed-demo.txt’ file using sed command as shown below.

The following sed command removes the first and last line from the file: # sed '1d $d' sed-demo.txtĩ Ubuntu 3) Deleting a particular line from a file To delete the first line from a file, use the following syntax:
#Xline helper 2d how to#
The first part shows how to use sed command to delete lines based on a position in the file. # cat sed-demo.txtġ0 openSUSE Part-I) Removing lines based on a position in the file To demonstrate sed command, we have created the ‘sed-demo.txt’ file and added the following contents with line numbers for better understanding. Note: Since this is a demonstration article, we use sed command without the -i option, which is similar to the “dry run” option, and will display the actual output without making any changes in the file.īut, if you would like to remove the lines from the source file in real environment then use the -i option with sed command. If you could memorize these commands, it will save a lot of your time when you have the requirement to perform various admin tasks in your projects.Īlso, check this article on how you can use the sed command to replace a matching string in a file. There are 27 examples listed in this article, which will help you to become a master in sed command.
