Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

from matched line till the next blank line 1

Status
Not open for further replies.

ogniemi

Technical User
Nov 7, 2003
1,041
PL
hello,

the input is:

Code:
ccccccccc
vvvvvvvvvvvv
bbbbbbbbbbb
abc fgg
sssssssssssssss
ssssssssssssssss
ssssssssssssssss

dddddddd
ffffffffff

ddddddddddddddd
def g
dddddddddd
ddddddddddddddd
ddddddddddddd

vvvvvvvv
abc h h
eeeeeeeeeeee
eeeeeeeeeeeee
eeeeeeeee

fffffffffff
gggggggggg

abc jh h
ffffffffffffffff
fffffffffffff
fffffffffff
[EOF]


how to get each from ^abc and from def^ till empty line (if in the last one the are no empty line then till end of file)
and finally get:

Code:
abc fgg
sssssssssssssss
ssssssssssssssss
ssssssssssssssss

def g
dddddddddd
ddddddddddddddd
ddddddddddddd

abc h h
eeeeeeeeeeee
eeeeeeeeeeeee
eeeeeeeee

abc jh h
ffffffffffffffff
fffffffffffff
fffffffffff


thank you in advance.
 
Hi

Code:
sed -n '/^\(abc\|def\)/,/^$/p' /path/to/input

[gray]# or[/gray]

awk '/^(abc|def)/,$0==""' /path/to/input
Tested with GNU [tt]sed[/tt], [tt]gawk[/tt] and [tt]mawk[/tt].

Feherke.
 
Hi

Oops, I forgot to mention one thing. If the starting "abc" and "def" are whole words, then better avoid regular expressions in the [tt]awk[/tt] solution :
Code:
awk '$1=="abc"||$1=="def",$0==""' /path/to/input
Tested with [tt]gawk[/tt] and [tt]mawk[/tt].

Feherke.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top