Text Processing – How to Remove Certain Lines by Line Numbers in a File

text processing

There are specific lines that I want to remove from a file. Let's say it's line 20-37 and then line 45. How would I do that without specifying the content of those lines?

Best Answer

With sed, like so:

sed '20,37d; 45d' < input.txt > output.txt

If you wanted to do this in-place:

sed --in-place '20,37d; 45d' file.txt