Delete every seventh line with sed

I need a sed script that deletes every seventh line in a file. I managed to do this with awk script, but I wanted to find a way to use sed for this.

+3
source share
2 answers

You can try

sed 'n;n;n;n;n;n;d;' 
+6
source

Sai's solution seems the best. However, if you use GNU sed and are not looking for portability, you can use the step address:

$ seq 1 10 | sed '0~3d'
1
2
4
5
7
8
10

The address n~mcorresponds to the entire k-th line, where k = n + m * i.

+4
source

All Articles