$ sed '/b/,~8 d' a-i.txt
I know what it does. But, they say "a multiple of 8" for ~8. Why is it expressed as "a multiple of 8"?
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It only takes a minute to sign up.
Sign up to join this community$ sed '/b/,~8 d' a-i.txt
I know what it does. But, they say "a multiple of 8" for ~8. Why is it expressed as "a multiple of 8"?
/b/,~8
matches lines starting with a line containing b
and continuing until a line is reached whose line number is a multiple of 8
From man sed
:
addr1,~N
Will matchaddr1
and the lines followingaddr1
until the next line whose input line number is a multiple ofN
.
This prints any line which contains 5
and all following lines up to and including the next line whose line number is a multiple of 8:
$ seq 14 | sed -n '/5/,~8 p'
5
6
7
8
This prints from a line containing 14 to the next line whose line number is a multiple of 8:
$ seq 22 | sed -n '/14/,~8 p'
14
15
16
This deletes all lines starting with a line matches 5
and ending with the next line whose line number is a multiple of 8:
$ seq 10 | sed '/5/,~8 d'
1
2
3
4
9
10
This prints the fourth line and every eigtht line thereafter:
$ seq 22 | sed -n '4~8 p'
4
12
20
This prints a line matching 4
and the next three lines which follow:
$ seq 13 | sed -n '/4/,+3 p'
4
5
6
7
seq 22 | sed -n '4~8 p'
into a terminal, press enter, and copy-and-paste the results to here. Once I get here, I need to indent it by four spaces. I do that by highlighting it and typing Ctrl-K.
– John1024
Dec 30 '17 at 8:25