I have text data at the command line that is broken into "records", each with the same value (always 1). In each record, each line is a separate key and value (no this isn't in json unfortunately). A key is sometimes repeated in the record, and sometimes the key name is part of a longer key. For example:
Record = 1
Apple = 1
Ball = 2
Car = 3
RedApple = 4
Ball = 5
Dog = 6
Elf = 7
Fudge = 8
Record = 1
Apple = 2
Ball = 4
Car = 6
RedApple = 8
Ball = 10
Dog = 12
Elf = 14
Fudge = 16
Record = 1
Apple = 3
Ball = 6
Car = 9
RedApple = 12
Ball = 15
Dog = 18
Elf = 21
Fudge = 24
Is there a quick for each record get the lines for a set of keys, returning only the first result per key?
Ex: For each record get keys {Apple, Ball, Dog}
would match the following lines:
Record = 1
Apple = 1
Ball = 2
Dog = 6
Record = 1
Apple = 2
Ball = 4
Dog = 12
...
Basically, the rule is after matching a line with "Record", get the next unique lines with " Apple ", " Ball ", and " Dog " (spacing indicating exact key match) and spit those lines out.
I can write something in perl and it wouldn't be too complex. I don't know awk, so don't know if it's better for something like this.