Write a code to print a sentence from a file with a matching condition, then optimize it in terms of space.