I want to know how to quickly delete text with Bash. For example, I have a file named file.txt with a total of 500 lines.

I want to delete lines 80 to 146 - how do I do that?

What's is a terminal command that can do that?

2 Answers 2


If this is one time I would use vi or vim

vi {filename}

That last one saves and quits. Using sed:

sed '86,146d' {file}

Make a backup if unsure so you can revert.


With awk to print in terminal:

awk 'NR < 80 || NR > 146' file.txt

Or with gawk to edit file in-place:

gawk -i inplace 'NR < 80 || NR > 146' file.txt

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .