perl -ne 'print && close ARGV' filename.txt