Awk过滤段落

时间:2015-08-14 00:44:06

标签: printing awk gawk

我有一个简单的txt文件,其中包含大约15-40行的段落,每个段落与前一个/下一个段落分开,有3个空行,我想打印出包含字符串的所有段落“ sasi89" 。

示例:

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

2 个答案:

答案 0 :(得分:2)

您可以通过将RS设置为空字符串,在“段落模式”中使用awk(请参阅https://www.gnu.org/software/gawk/manual/html_node/Multiple-Line.html):

awk -v RS= '/sasi89/' file

以上假设您的文件中除了段落之间没有其他空白行。

答案 1 :(得分:1)

要求救援

awk 'BEGIN{ORS=RS="\n\n\n"} /sasi89/'    

这将在段落之间保留3个空行。如果您想要标准化为单个空行,请删除ORS=或简单地

awk -v RS="\n\n\n" '/sasi89/'