Brian J. Murrell
2012-12-12 18:13:10 UTC
Hi,
So I have some text in which there is a block, delimited by a pattern
and within that block I want to print a line of text by it's line
number, relative to the start of the block. So, given the input:
a
b
c
d
e
f
g
h
i
j
k
l
m
within the block starting at 'd' and ending with the blank like I want
to print the third line, so in this case the line with the "f" on it.
I am constrained to matching the /d/,/^$/ block by patterns and the
block could be anywhere in a file so I won't know any line numbers ahead
of time.
Extracting the block is simple enough:
/d/,/^$/
but once I have that block how can I address into it relative the the
first line of the block since the block still has it's absolute line
numbers.
i.e. /d/,/^$/{
=
}
will print:
4
5
6
7
8
9
And of course the beginning pattern will not always occur on the same line.
I tried a hold space and replacing the pattern space with the hold space
but that seemed to retain the original line number addressing once it
was brought into the pattern space.
Any ideas on how to achieve this?
Cheers,
b.
[Non-text portions of this message have been removed]
So I have some text in which there is a block, delimited by a pattern
and within that block I want to print a line of text by it's line
number, relative to the start of the block. So, given the input:
a
b
c
d
e
f
g
h
i
j
k
l
m
within the block starting at 'd' and ending with the blank like I want
to print the third line, so in this case the line with the "f" on it.
I am constrained to matching the /d/,/^$/ block by patterns and the
block could be anywhere in a file so I won't know any line numbers ahead
of time.
Extracting the block is simple enough:
/d/,/^$/
but once I have that block how can I address into it relative the the
first line of the block since the block still has it's absolute line
numbers.
i.e. /d/,/^$/{
=
}
will print:
4
5
6
7
8
9
And of course the beginning pattern will not always occur on the same line.
I tried a hold space and replacing the pattern space with the hold space
but that seemed to retain the original line number addressing once it
was brought into the pattern space.
Any ideas on how to achieve this?
Cheers,
b.
[Non-text portions of this message have been removed]