

However, this sed do not remove the lines that contain spaces. The ^$ indicates sed command to delete empty lines. You can specify the list of lines you want to remove in sed command with semicolon as a delimiter. Here the sed command removes lines other than 2nd, 3rd and 4th. Delete lines other than the specified range Delete lines other than last line or footer lineħ. The following sed command removes all the lines except the header line.Ħ. Use the negation (!) operator with d option in sed command. Delete lines other than the first line or header line

The following sed command deletes the lines ranging from 2 to 4:ĥ. The sed command removes the lines from m to n in the file. Here m and n are min and max line numbers. The sed command can be used to delete a range of lines. The below sed command removes the second line in a file. The following sed command is used to remove the footer line in a file. Delete last line or footer line or trailer line In the following example, the sed command removes the first line in a file.Ģ. The d option in sed command is used to delete a line. In the following examples, the sed command removes the lines in file that are in a particular position in a file. Sed Command to Delete Lines - Based on Position in File The following file contains a sample data which is used as input file in all the examples:
#File command in unix how to#
Here we will see how to delete lines using sed command with various examples. Sed Command to Delete Lines: Sed command can be used to delete or remove specific lines which matches a given pattern or in a particular position in a file.
