Thursday, 28 July 2011

Perl One Liner: Delete files with wrong number of lines

Just a quick perl one liner for future reference. I needed to delete some text files that didn't have the correct number of lines as they would break a downstream R script to parse the results
for f in *.txt;do perl -ne 'END{unlink $ARGV unless $.==200}' ${f} ;done
I always forget that $ARGV is the variable for the input file name in a one-liner.

No comments:

Post a Comment