Today (Saturday) We will make some minor tuning adjustments to MySQL.

You may experience 2 up to 10 seconds "glitch time" when we restart MySQL. We expect to make these adjustments around 1AM Eastern Daylight Saving Time (EDT) US.


Processing a formatted file with awk


Login or Register to Reply

 
Thread Tools Search this Thread
# 1  
Processing a formatted file with awk

Hi - I want to interrogate information about my poker hands, sessions are all recorded in a text file in a particular format. Each hand starts with the string <PokerStars> followed by a unique hand reference and other data like date/time. There is then all the information about each hand. My first requirement is to create separate files for each hand (to be interrogated later). Below is an extract of two of the hands to illustrate. What I'd like is to parse the first line, extract the unique hand reference, sub the # and :, this will be the file name, print the first line to the file name and then print all information about that hand to the file name. Then repeat for each hand. So in the examples below two files would be created: 198068432137 and 198068457380 containing each line of text about each hand. Once all the files per hand are created I'll then move onto the next task of extracting common elements of play.
I've written a script in bash but it takes 2 seconds to create each file and there are thousands of hands. If I use awk I can print the first line based on the <PokerStars> string in an instant on the whole file but I'm not sure how to formulate the file name and append all the relevant hand data to it. Can someone please offer a solution using awk or something that is quick to parse ?

Code:
PokerStars Hand #198068432137:  Hold'em No Limit ($0.25/$0.50 USD) - 2019/03/12 23:40:28 WET [2019/03/12 19:40:28 ET]
Table 'Hektor III' 6-max Seat #3 is the button
Seat 1: yarfrost ($63.28 in chips)
Seat 2: Manifestorr ($92.50 in chips)
Seat 3: AADublin ($30.80 in chips)
Seat 4: bobster2303 ($37.68 in chips)
Seat 5: Ireful ($50.08 in chips)
Seat 6: trofim-tro ($82.67 in chips)
bobster2303: posts small blind $0.25
Ireful: posts big blind $0.50
*** HOLE CARDS ***
Dealt to bobster2303 [8h Kh]
trofim-tro: folds
yarfrost: folds
Manifestorr: folds
AADublin: calls $0.50
bobster2303: calls $0.25
Ireful: raises $2.50 to $3
AADublin: calls $2.50
bobster2303: folds
*** FLOP *** [9h 5s 9s]
Ireful: checks
AADublin: checks
*** TURN *** [9h 5s 9s] [6d]
Ireful: checks
AADublin: checks
*** RIVER *** [9h 5s 9s 6d] [5h]
Ireful: checks
AADublin: checks
*** SHOW DOWN ***
Ireful: shows [As Qd] (two pair, Nines and Fives)
AADublin: mucks hand
Ireful collected $6.18 from pot
*** SUMMARY ***
Total pot $6.50 | Rake $0.32
Board [9h 5s 9s 6d 5h]
Seat 1: yarfrost folded before Flop (didn't bet)
Seat 2: Manifestorr folded before Flop (didn't bet)
Seat 3: AADublin (button) mucked [7c Qc]
Seat 4: bobster2303 (small blind) folded before Flop
Seat 5: Ireful (big blind) showed [As Qd] and won ($6.18) with two pair, Nines and Fives
Seat 6: trofim-tro folded before Flop (didn't bet)


Code:
PokerStars Hand #198068457380:  Hold'em No Limit ($0.25/$0.50 USD) - 2019/03/12 23:41:18 WET [2019/03/12 19:41:18 ET]
Table 'Hektor III' 6-max Seat #4 is the button
Seat 1: yarfrost ($63.28 in chips)
Seat 2: Manifestorr ($92.50 in chips)
Seat 3: AADublin ($27.80 in chips)
Seat 4: bobster2303 ($37.18 in chips)
Seat 5: Ireful ($53.26 in chips)
Seat 6: trofim-tro ($82.67 in chips)
Ireful: posts small blind $0.25
trofim-tro: posts big blind $0.50
*** HOLE CARDS ***
Dealt to bobster2303 [2h 7s]
yarfrost: folds
Manifestorr: folds
AADublin: raises $1 to $1.50
bobster2303: folds
Ireful: folds
trofim-tro: calls $1
*** FLOP *** [6s 9h 3s]
trofim-tro: checks
AADublin: bets $1.55
trofim-tro: folds
Uncalled bet ($1.55) returned to AADublin
AADublin collected $3.09 from pot
AADublin: doesn't show hand
*** SUMMARY ***
Total pot $3.25 | Rake $0.16
Board [6s 9h 3s]
Seat 1: yarfrost folded before Flop (didn't bet)
Seat 2: Manifestorr folded before Flop (didn't bet)
Seat 3: AADublin collected ($3.09)
Seat 4: bobster2303 (button) folded before Flop (didn't bet)
Seat 5: Ireful (small blind) folded before Flop
Seat 6: trofim-tro (big blind) folded on the Flop

Moderator's Comments:
Mod Comment Please use code tags to format data

Last edited by jim mcnamara; 03-12-2019 at 10:39 PM..
# 2  
Have you written any code? At all?

I do not see where the content of any of the hands is displayed except when one person calls another. I think we need to get a lot more information from you to go any further.
# 3  
I did not understand everything. But test it.
Code:
awk '
/^PokerStars/   {if (FN) close (FN)
                  FN = gensub(/[^0-9]/, "", "g", $3)
                }
                { print > FN
                }' file

# 4  
Not all "awk" implementations have "gensub" function. If the above does not work
Code:
awk '
/^PokerStars/   { if (FN) close(FN)
                 match($3, /[0-9]+/)
                 FN = substr($3, RSTART, RLENGTH)
                }
                { print > FN
                }' file

# 5  
No (gen)sub needed:
Code:
awk -F"[#:]" '/^PokerStar/ {if (FN) close (FN); FN = $2} {print > FN}' file

I wouldn't call that a "formatted file", btw. A text file with some repeated (not even periodic!) patterns, perhaps.

Last edited by RudiC; 03-13-2019 at 06:46 AM..
This User Gave Thanks to RudiC For This Post:
# 6  
Related, somewhat off-topic

Hi.

I was reading an article in the AI issue of IEEE Spectrum. Perhaps it will be of interest ... cheers, drl
Quote:
Similar claims are being made about a new poker-playing program from a team at the University of Alberta, in Canada, called DeepStack, which has trounced human opponents in Texas hold ’em. The researchers write that it “plays using ‘intuition’ honed through deep learning to reassess its strategy with each decision.” To me, having little poker experience, this was a revelation: Contrary to my naive belief that winning at poker was based on psyching out opponents, poker is really a game of strategy. And the computer has learned a better strategy than we have discovered on our own.
Can Machine Learning Teach Us Anything? - IEEE Spectrum

DeepStack

Texas Hold'em AI Bot Taps Deep Learning to Demolish Humans - IEEE Spectrum
This User Gave Thanks to drl For This Post:
Login or Register to Reply

|
Thread Tools Search this Thread
Search this Thread:
Advanced Search

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Help with file processing using awk

hello All, I'm new to AWK programming and learned myself few things to process a file and deal with duplicate lines, but I got into a scenario which makes me clueless to handle. Here is the scenario.. Input file: user role ----- ---- AAA add AAA delete BBB delete CCC delete DDD ... (10 Replies)
Discussion started by: julearn
10 Replies

2. Shell Programming and Scripting

awk operation to get table formatted file

I need to parse .conf file in Unix system to get output from the snippets like below : ; generated by mod_identity exten => int,1,GoSub(mdc_template-3,s,1) exten => int,n(next_380),Return() ; default action for busy exten => ext,1,GoSub(mdc_template-3,s,1) exten => ext,n,Set(PRI_CAUSE=17)... (2 Replies)
Discussion started by: cheecky
2 Replies

3. Programming

awk processing / Shell Script Processing to remove columns text file

Hello, I extracted a list of files in a directory with the command ls . However this is not my computer, so the ls functionality has been revamped so that it gives the filesizes in front like this : This is the output of ls command : I stored the output in a file filelist 1.1M... (5 Replies)
Discussion started by: ajayram
5 Replies

4. Shell Programming and Scripting

Help with File Processing (AWK)

Input File: 1234, 2345,abc 1,24141,gw 222,rff,sds 2232145,sdsd,121 Output file to be generated: 000001234,2345,abc 000000001,24141,gw 000000222,rff,sds 002232145,sdsd,121 i.e; the first column is padded to get 9 digits. I tried with following: (3 Replies)
Discussion started by: karumudi7
3 Replies

5. Shell Programming and Scripting

Help with File Processing (AWK)

Input File: 1234, 2345,abc 1,24141,gw 222,rff,sds 2232145,sdsd,121 Output file to be generated: 000001234,2345,abc 000000001,24141,gw 000000222,rff,sds 002232145,sdsd,121 i.e; the first column is padded to get 9 digits. I tried with following: (1 Reply)
Discussion started by: karumudi7
1 Replies

6. Programming

AWK processing of a three-column file

I have a 3-column data file, for which I wish to print certain parts of $3 PHI PSI A(x) -177.5 -177.5 1.0625 -177.5 -172.5 0.55 -177.5 -167.5 0.0478125 -177.5 -162.5 0 -177.5 -157.5 0.284375 -177.5 -152.5 0.187188 -177.5 -147.5 0.236875 -177.5 -142.5 0.383438 -177.5 ... (3 Replies)
Discussion started by: chrisjorg
3 Replies

7. Shell Programming and Scripting

awk, sed, perl assistance in outputting formatted file

Hello, Please advise. Scoured this site, as well as google for answers. However if you do not know what to search for, it's a bit hard to find answers. INPUT: ACTASS= 802 BASECOS= 279 COSNCHG= 3 CUSCOS= 52 UPLDCOS= 2 DESIRED OUTPUT: ACTASS=802 BASECOS=279 (13 Replies)
Discussion started by: abacus
13 Replies

8. Shell Programming and Scripting

awk help in processing file.

I am trying to process file which has following data #23456789012345 ACNASPSA13N0N0 ACNAPCPA05N0N0 ACNAFATS11N0N0 I want to take out each line from the file and what to put in the file by name which if part of the line starting from offset 10 to 15. It means I want to create three file... (3 Replies)
Discussion started by: ekb
3 Replies

9. Shell Programming and Scripting

how to change the current file processing to some other random file in awk ?

Hello, say suppose i am processing an file emp.dat the field of which are deptno empno empname etc now say suppose i want to change the file to emp.lst then how can i do it? Here i what i attempted but in vain BEGIN{ system("sort emp.dat > emp.lst") FILENAME="emp.lst" } { print... (2 Replies)
Discussion started by: salman4u
2 Replies

10. Shell Programming and Scripting

processing a file with sed and awk

Hello, I have what is probably a simple task in text manipulation, but I just can't wrap my brain around it. I have a text file that looks something like the following. Note that some have middle initials in the first field and some don't. john.r.smith:john.smith@yahoo.com... (4 Replies)
Discussion started by: manouche
4 Replies

Featured Tech Videos