Suppose we have one line of text stored in a file:
// In the actual file this will be one line
{unrelated_text1,ID:13, unrelated_text2,TIMESTAMP:1476280500,unrelated_text3},
{other_unrelated_text1,other_unrelated_text2,ID:25,TIMESTAMP:1476280600},
{ID:30,more_unrelated_text1,TIMESTAMP:1476280700},
{ID:40,final_unrelated_text}
What I want is for this particular input extract 3 entries:
// The details, such as whether to put { character in front or not do not matter.
// Any form of output which extracts only these 3 entries and groups them in a
// visually nice way will do the job.
{ID:13, TIMESTAMP:1476280500}
{ID:25, TIMESTAMP:1476280600}
{ID:30, TIMESTAMP:1476280700}
// I do not want the last entry, because it does not contain timestamp field.
So far the closest command I found is
grep -Po {ID:[0-9]+(.+?)} input_file
which gives the output
{unrelated_text1,ID:13,unrelated_text2,TIMESTAMP:1476280500,unrelated_text3}
{other_unrelated_text1,other_unrelated_text2,ID:25,TIMESTAMP:1476280600}
{ID:30,more_unrelated_text1,TIMESTAMP:1476280700}
{ID:40,final_unrelated_text}
The next improvement I am searching for is how to remove unrelated_text from each entry and also remove the last entry.
Question: what's the shortest way to do that in Linux?