Next line matching the regex in bash
Posted
by Lin_freak
on Stack Overflow
See other posts from Stack Overflow
or by Lin_freak
Published on 2010-06-17T14:02:47Z
Indexed on
2010/06/17
14:23 UTC
Read the original article
Hit count: 140
bash
I have a file in the format:
Port Number
IP address
Port Number
IP address
(Not sure how the output will be displayed here but let me tell you they are on separate lines)
and so on....
I use the command grep -C 1 'port number' file.txt
i.e. I want all IP addresses corresponding to a particular port. Making it simple, I want the next line matching a regular expression. Like if my regular expression matches line 2,4 and 6 then I want lines 3, 5 and 7 to be printed. How to do that?
© Stack Overflow or respective owner