Use shell variable in perl command line

Hi,

I would like to use a shell variable

$amp

in my perl command line.

	for fa in $WORKSPACE/*.fa; do
	
		amp=`grep ">.*" $fa | sed -e's#>\(.*\)#\1#g'`
		ampsam="$WORKSPACE/$base/$base.$amp.sam"
		sqheader=`grep "^@SQ.*SN:$amp.*" $sam`

		printf "$sqheader\n" >> $ampsam
		
		#lines=`grep ".*\:.*\:.*$amp.*" $sam` # | sed 's/%/%%/'` #this also includes the @SQ line.
		
		perl -n -e 'if($_=~/.*\:.*\:.*$amp/){print "$_";}' $sam >> $ampsam

	done

Is there a way to do this?

There are few ways actually. I think this is the most elegant:

perl -s -n -e 'if($_=~/.*\:.*\:.*$amp/){print "$_";}' -- -amp="$amp" $sam >> $ampsam
1 Like

Worked like a charm. Is there any decent documentation on using command line perl? Every time I google 'command line' and 'perl' together I get hits for passing arguments to a perl script.

Enjoy: perlrun - perldoc.perl.org

1 Like