Use shell variable in perl command line


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Use shell variable in perl command line
# 1  
Old 10-16-2013
Use shell variable in perl command line

Hi,

I would like to use a shell variable
Code:
$amp

in my perl command line.

Code:
	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?
# 2  
Old 10-16-2013
There are few ways actually. I think this is the most elegant:
Code:
perl -s -n -e 'if($_=~/.*\:.*\:.*$amp/){print "$_";}' -- -amp="$amp" $sam >> $ampsam

This User Gave Thanks to bartus11 For This Post:
# 3  
Old 10-16-2013
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.
# 4  
Old 10-16-2013
This User Gave Thanks to bartus11 For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to read the output of a command line by line and pass it as a variable?

Hi, I have some 2000 names in a table like below. Java Oracle/SQL ANSI SQL SQL,DWH,DB DB&Java And by using for loop in my code i am able to get a single word but if there is any special character or space then it is considering as a next line. I have to execute the below queries in... (10 Replies)
Discussion started by: Samah
10 Replies

2. Shell Programming and Scripting

Perl command line option '-n','-p' and multiple files: can it know a file name of a printed line?

I am looking for help in processing of those options: '-n' or '-p' I understand what they do and how to use them. But, I would like to use them with more than one file (and without any shell-loop; loading the 'perl' once.) I did try it and -n works on 2 files. Question is: - is it possible to... (6 Replies)
Discussion started by: alex_5161
6 Replies

3. Shell Programming and Scripting

Usage of shell variable in perl command

Hi, I have a shell script, In which i have variable "var1" and some perl command inside shell script. export var1='coep -n rst-a2p-hinje.vci.all.com -c' perl -pi -e 's/^/coep -n rst-a2p-hinje.vci.all.com -c /' command.txt currently I am adding value of var1 in command.txt file by... (2 Replies)
Discussion started by: rakeshtomar82
2 Replies

4. Shell Programming and Scripting

How to read a two files, line by line in UNIX script and how to assign shell variable to awk ..?

Input are file and file1 file contains store.bal product.bal category.bal admin.bal file1 contains flip.store.bal ::FFFF:BADC:CD28,::FFFF:558E:11C5,6,8,2,1,::FFFF:81C8:CA8B,::FFFF:BADC:CD28,1,0,0,0,::FFFF:81C8:11C5,2,1,0,0,::FFFF:81DC:3111,1,0,1,0 store.bal.... (2 Replies)
Discussion started by: veeruasu
2 Replies

5. Shell Programming and Scripting

Embeded shell variable in command line

Hello, I know this is a situation about the single quote and double literal, but I could not figure out after many search. I need to loop through thousands of different BACs sequencing to optimize kmer individually. IN=/PATH/TO/INPUT/FILES for sample in S{01..1096} do run_program... (9 Replies)
Discussion started by: yifangt
9 Replies

6. Shell Programming and Scripting

PERL or SHELL Scrript to search in Directories by taking line by line from a text file

Unix box server version *********** >uname -r B.11.00 >echo $SHELL /usr/bin/ksh --> in this server, I have the path like /IMbuild/dev/im0serv1 ---> in that directory I have the folders startup(.jsp files nearly 100 jsp's ) and scripts(contains .js files nearly 100 files) ... (9 Replies)
Discussion started by: pasam
9 Replies

7. Shell Programming and Scripting

Passing perl variable to shell command

Can we pass perl variable to shell commands. If yes, please give some example. (2 Replies)
Discussion started by: Anjan1
2 Replies

8. Shell Programming and Scripting

perl/unix: script in command line works but not in perl

so in unix this command works works and shows me a list of directories find . -name \*.xls -exec dirname {} \; | sort -u | > list.txt but when i try running a perl script to run this command my $query = 'find . -name \*.xls -exec dirname {} \; | sort -u | > list.txt';... (2 Replies)
Discussion started by: kpddong
2 Replies

9. Shell Programming and Scripting

Insert a line including Variable & Carriage Return / sed command as Variable

I want to instert Category:XXXXX into the 2. line something like this should work, but I have somewhere the wrong sytanx. something with the linebreak goes wrong: sed "2i\\${n}Category:$cat\n" Sample: Titel Blahh Blahh abllk sdhsd sjdhf Blahh Blah Blahh Blahh Should look like... (2 Replies)
Discussion started by: lowmaster
2 Replies

10. Shell Programming and Scripting

Perl script variable to read shell command

Solaris 10 Korn shell ksh, Hi there, I have figured out to get yesterday's date which is using the below command: TZ=GMT+24; date +%d-%b-%Y to get the format of 30-Sep-2008 and TZ=GMT+24; date +%Y%m%d to get the format of 20080930. I need this two format. In my perl script below I need... (4 Replies)
Discussion started by: bulkbiz
4 Replies
Login or Register to Ask a Question