correctly deal with multi columns from stdin; optimization: read each line once