How to remove every other line with sed?

GNU sed has a suitable addressing mode:

sed -n '1~2!p' file

which means, starting from line 1, and with step 2, print all other lines.

Equivalently, you can drop the -n, and delete matching lines:

sed '1~2d'

It can also be done using awk:

awk 'NR%2==0' file

(Whenever line number is a multiple of 2, print the line)

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)