Stupid grep (actually, a lot of grep, because didn't find how to use groups in grep)