SED (Linux) – Ranges by line number

You can specify a range on line numbers by inserting a comma between the numbers. To restrict a substitution to the first 100 lines, you can use:

sed '1,100 s/A/a/'

If you know exactly how many lines are in a file, you can explicitly state that number to perform the substitution on the rest of the file. In this case, assume you used wc to find out there are 532 lines in the file:

sed '101,532 s/A/a/'

An easier way is to use the special character "$", which means the last line in the file.

sed '101,$ s/A/a/'

The "$" is one of those conventions that mean "last" in utilities like cat -evi, and ed. "cat -e" Line numbers are cumulative if several files are edited. That is:

sed '200,300 s/A/a/' f1 f2 f3 >new

is the same as:

cat f1 f2 f3 | sed '200,300 s/A/a/' >new