in reply to bash loop passing to perl command line

Do not enclose the variable to be expanded into single quotes:
for i in 1 2 3 4 5 6 7 10 11 12 ; do perl -lane 'print p'$i'. "\t$_"' p$i.chr7.miRNA.txt done

Replies are listed 'Best First'.
Re^2: bash loop passing to perl command line
by ikegami (Patriarch) on Oct 27, 2011 at 05:31 UTC

    Drop out of single quotes:

    for i in 1 2 3 4 5 6 7 10 11 12 ; do perl -lane'print "p'$i'\t$_"' p$i.chr7.miRNA.txt done

    Or use double quotes: (Don't forget to escape what needs to be escaped.)

    for i in 1 2 3 4 5 6 7 10 11 12 ; do perl -lane"print qq{p$i\\t\$_}" p$i.chr7.miRNA.txt done

    Or pass it as an argument:

    for i in 1 2 3 4 5 6 7 10 11 12 ; do perl -lane'BEGIN { $i = shift(@ARGV); } print "p$i\t$_"' $i p$i.chr7.miRNA.txt done