How to delete line number 3,6,9,12,15 and so on?

Hello,

How can I remove line number 3,6,9,12,15,18 and so on for a text file using sed? The line number pattern is multiple 3.

Thanks in advance.

awk 'NR%3' file
2 Likes

You mean the line or the line numbers?

sed 'n;n;d' file

GNU sed:

sed 0~3d file
1 Like

Dear ahamed101,

I mean 3rd, 6th, 9th, 12th, 15th line and so on. Thanks. It is solved.

awk ' NR/3 ~ /\./ ' file
1 Like

@anbu: Novel approach, to force the number into string context. It brings with it, however, that it is implementation dependent whether locale is used to convert it and whether a "." is part of the string..

In BSD awk, for example it will not work with the wrong locale:

$ printf "%s\n" {1..17} | LC_NUMERIC=nl_NL awk ' NR/3 ~ /\./ '
$
$ printf "%s\n" {1..17} | LC_NUMERIC=en_US awk ' NR/3 ~ /\./ '
1
2
4
5
7
8
10
11
13
14
16
17
1 Like