Reputation: 444
I have a plain txt file which contains paragraphs which contain about 15-40 lines and each paragraph is separated from the previous/next one with 3 empty lines, I'd like to print out all the paragraphs which contain the string "sasi89".
Example:
PokerStars Hand #61919020230: Tournament #393199063, $0.10+$0.01 USD Hold'em No Limit - Level IV (50/100) - 2011/05/10 12:11:58 ET
Table '393199063 1' 9-max Seat #9 is the button
Seat 1: bebe2829 (1529 in chips)
Seat 3: zng 111 (4374 in chips)
Seat 4: mal4o (11100 in chips)
Seat 6: gysomi (6118 in chips)
Seat 7: DEEAMAYA (2590 in chips)
Seat 9: sasi89 (235 in chips)
bebe2829: posts small blind 50
zng 111: posts big blind 100
*** HOLE CARDS ***
Dealt to sasi89 [Kc Th]
mal4o: folds
gysomi: folds
DEEAMAYA: folds
sasi89: raises 135 to 235 and is all-in
bebe2829: folds
zng 111: calls 135
*** FLOP *** [7h 9s Tc]
*** TURN *** [7h 9s Tc] [Qd]
*** RIVER *** [7h 9s Tc Qd] [9d]
*** SHOW DOWN ***
zng 111: shows [Jh Kh] (a straight, Nine to King)
sasi89: shows [Kc Th] (two pair, Tens and Nines)
zng 111 collected 520 from pot
sasi89 finished the tournament in 11th place
*** SUMMARY ***
Total pot 520 | Rake 0
Board [7h 9s Tc Qd 9d]
Seat 1: bebe2829 (small blind) folded before Flop
Seat 3: zng 111 (big blind) showed [Jh Kh] and won (520) with a straight, Nine to King
Seat 4: mal4o folded before Flop (didn't bet)
Seat 6: gysomi folded before Flop (didn't bet)
Seat 7: DEEAMAYA folded before Flop (didn't bet)
Seat 9: sasi89 (button) showed [Kc Th] and lost with two pair, Tens and Nines
PokerStars Hand #61918994165: Tournament #393199063, $0.10+$0.01 USD Hold'em No Limit - Level IV (50/100) - 2011/05/10 12:11:19 ET
Table '393199063 1' 9-max Seat #7 is the button
Seat 1: bebe2829 (1079 in chips)
Seat 3: zng 111 (4374 in chips)
Seat 4: mal4o (11500 in chips)
Seat 6: gysomi (6118 in chips)
Seat 7: DEEAMAYA (2590 in chips)
Seat 9: sasi89 (285 in chips)
sasi89: posts small blind 50
bebe2829: posts big blind 100
*** HOLE CARDS ***
Dealt to sasi89 [2d 7h]
zng 111: folds
mal4o: calls 100
gysomi: folds
DEEAMAYA: folds
sasi89: folds
bebe2829: checks
*** FLOP *** [8c Js 2h]
bebe2829: checks
mal4o: checks
*** TURN *** [8c Js 2h] [8h]
bebe2829: checks
mal4o: checks
*** RIVER *** [8c Js 2h 8h] [6h]
bebe2829: bets 300
mal4o: calls 300
*** SHOW DOWN ***
bebe2829: shows [Jc 3c] (two pair, Jacks and Eights)
mal4o: mucks hand
bebe2829 collected 850 from pot
*** SUMMARY ***
Total pot 850 | Rake 0
Board [8c Js 2h 8h 6h]
Seat 1: bebe2829 (big blind) showed [Jc 3c] and won (850) with two pair, Jacks and Eights
Seat 3: zng 111 folded before Flop (didn't bet)
Seat 4: mal4o mucked [6d Ac]
Seat 6: gysomi folded before Flop (didn't bet)
Seat 7: DEEAMAYA (button) folded before Flop (didn't bet)
Seat 9: sasi89 (small blind) folded before Flop
Upvotes: 0
Views: 175
Reputation: 203985
You can use awk in "paragraph mode" (see https://www.gnu.org/software/gawk/manual/html_node/Multiple-Line.html) by setting RS
to the empty string:
awk -v RS= '/sasi89/' file
The above assumes there's no other blank lines in your file except those between paragraphs.
Upvotes: 2
Reputation: 67507
awk to the rescue
awk 'BEGIN{ORS=RS="\n\n\n"} /sasi89/'
this will keep the 3 empty lines between paragraphs. If you want to normalize to single empty line remove ORS=
or simply
awk -v RS="\n\n\n" '/sasi89/'
Upvotes: 1