I do feel about not doing this in sed but I couldn't make it work