I have a file full of records in the following format:
{TOKEN
{ NAME {name of this token} }
{ GROUPS {Group 1} }
{ VALUE value }
{ REPEATING {
{ MAX 3 }
{ TIME {nmin 30} }
} }
{ WINDOW */*/*/* }
{ ACTION {
{ EXEC {code to run here} }
} }
}
{TOKEN
{ NAME {name of next token} }
{ GROUPS {Group 1} }
{ VALUE value }
{ WINDOW 0/0:30-2:00,3:30-7:30/*/* }
{ HOST {localhost} }
{ ACTION {
{ email {
{ FROM cloverleaf@healthvision.com }
{ TO me@xxxx.org }
{ SUBJ {email subject test} }
{ MSG {this is the email body} }
} }
} }
Not all of the records have the same keywords but they all are nested keyed lists and I need to parse them into a .csv file for easier review. However, when I read in the file, it comes in as a single string rather than as a list of keyed lists. Splitting on whitespace or newline wouldn't help because they are located inside the keyed lists too. I tried to insert a pipe (|) between }\n and {T and split on the pipe but I still ended up with strings.
I hope someone can point me in the right direction to parse these s-expression files.
thanks in advance!
J