Deleting first line: sed ‘1d’ filename
Deleting particular line: sed ‘3d’ filename 🡪 deletes the third line
Deleting Last line: sed ‘$d’ filename
Deleting the range of line: sed ‘1,4d’ filename 🡪 deletes from 1 to 4th line
Deleting other than range of line: sed ‘1,4!d’ filename 🡪 it deletes other than 1 to 4th line
Deleting first and last line: sed ‘1d;$d’ filename 🡪 multiple commands separated by colon
Starting with L : sed ‘/^L/d’ filename 🡪 deletes the line starting with L
Ending with L : sed ‘/L$/d’ filename 🡪 deletes the line ending with L
Ending with l or L : sed ‘/[xX]$/d’ filename 🡪 deletes the line with l or L
Empty or Blank space line: sed ‘/^ *$/d’ filename
Containing specific pattern: sed ‘/Linux/d’ filename 🡪 deletes the line containing linux
Deletes from the first line to pattern matching 🡪 sed ‘1, /Linux/d’ filename
Deletes from pattern matching to last line of the file 🡪 sed ‘/Linux/,$d’ filename
Deleting all other lines other than matching pattern 🡪 sed ‘/linux/!d’ filename
Delete Empty line in file
sed ‘/^$/d’ filename
Deleting Multiple Blank lines
/^$/{
N
/^\n$/D
}
No comments:
Post a Comment