works for file or stdin