perl - Performing a one-liner on multiple input files specified by extension -
i'm using following line split , process tab-delimited .txt file:
perl -lane 'next unless $. >30; @array = split /[:,\/]+/, $f[2]; print if $array[1]/$array[2] >0.5 && $array[4] >2' input.txt > output.txt
is there way alter one-liner in order perform on multiple input files without specifying each individually?
ideally accomplished performing on files within current directory holding .txt (or other) file extension - , outputting set of modified files names e.g.:
input:
test1.txt test2.txt
output:
test1mod.txt test2mod.txt
i know can access filename modify $argv
not know how go getting run on multiple files.
solution:
perl -i.mod -lane 'next unless $. >30; @array = split /[:,\/]+/, $f[2]; print if $array[1]/$array[2] >0.5 && $array[4] >2; close argv if eof;' *.txt
$.
needs reset otherwise throws division 0 error.
if don't mind different output file name,
perl -i.mod -lane' next unless $. >30; @array = split /[:,\/]+/, $f[2]; print if $array[1]/$array[2] >0.5 && $array[4] >2; close argv if eof; # reset $. each file. ' *.txt
Comments
Post a Comment