SED Delete lines with their numbers from text file

Here is the tip to to print/delete the lines based on their line numbers:

  • To delete lines from 1 to 4
$ sed '1,4d' input.txt

This will print all lines by excluding line numbers 1 to 4 form input.txt

  • To delete line other than 1to 4
$sed '1,4!d' input.txt

This will print lines form 1 to 4.

  • To delete lines 1 to 4 in a input.txt use following command
$sed -i '1,4d' input.txt
  • To Delete only line number 4:
$sed -i '4d' input.txt

-Sany

Advertisements

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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