This is a small post on how to delete a line from a file when it matched some criteria. We can use many tools and languages like sed, awk, grep, python, perl, ruby etc. In this post we specifically use SED which is by default installed in Linux.

SED is a powerful tool which is useful for text file modifications. GNU SED have one capability to edit files directly by using -i which is insert.

To delete a line from a file use below code

	sed '/<search-pattern>/d' filename

// is used for searching a pattern and 'd' is used for deleting that line.
Example: Search for a line which contain tata and remove that line.

	sed '/Managing/d' Jumpcloud

Output:

	[email protected]:~$ cat Jumpcloud 

	Creating users?

	Managing users?

	Deleting users?

	[email protected]:~$ sed '/Managing/d' Jumpcloud 

	Creating users?

	Deleting users? [email protected]:~$

But this command will not update actual fill. In order to update use -i as mention earlier

	sed -i '/<search-pattern>/d' filename

Example:

	[email protected]:~$ cat Jumpcloud 

	Creating users?

	Managing users?

	Deleting users?

	[email protected]:~$ sed -i '/Managing/d' Jumpcloud 

	[email protected]:~$ cat Jumpcloud 

	Creating users?

	Deleting users?