Delete a line from text file with line number using sed


Sed is a stream editor for filtering and transforming text.

With sed we can delete a line using its line number without opening the text file.

Lets test with a example:

$ cat input.txt 





input.txt contains 4 lines with content as shown above.

Now I would like to delete line number 3 from input.txt

$ sed -i "3d" input.txt

$ cat input.txt




After running sed command as shown above just check the input.txt file where we can see that line 3 will be deleted.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s