---- Perl One-Liners ----

Running programs on multiple input files

Perl can be used as a wrapper to apply the same process to multiple input files but naming the output according to the original file.
  1. Bowtie mapping of multiple files to output files without the '.fastq' ending:
    perl -e 'foreach (@ARGV) { ($out = $_) =~ s/\.fastq//; system "bowtie2 index_file \"$_\" > \"$out.sam\"" 2> \"$out.log\"";}' *.fastq
  2. Transform SAM to BAM files:
    perl -e 'foreach (@ARGV) {($out = $_) =~ s/\.sam//; system "time samtools view \"$_\" > \"$out.bam\" 2> $out.err";}' *.sam 
  3. Sort and index BAM files:
    perl -e 'foreach (@ARGV) {($out = $_) =~ s/\.bam//; system "time samtools sort \"$_\" \"$out.sorted\"; time samtools index \"$out.sorted.bam\"";}' *.bam
  4. Change multiple WIG files into IGB files:
    perl -e 'foreach (@ARGV) { ($out = $_) =~ s/\.wig/.gr/; system "grep -v variable \"$_\" > \"$out\"";}' *tpm.wig
  5. Find all files in the current directory that have not been modified within the last 14 days and print their names together with the date they were last modified:
    perl -e 'foreach (<*>) { if (-M > 14) { $age = (stat($_))[9]; print "$_\t".(localtime($age))."\n";}}'