Usage of shell variable in perl command


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Usage of shell variable in perl command
# 1  
Old 09-14-2015
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.
Code:
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 hardcoded.
can I write a perl command which will get the vlaue from variable "var1" and add it to the command.txt file.


Thanks

Last edited by vbe; 09-14-2015 at 09:29 AM..
# 2  
Old 09-14-2015
Quote:
Originally Posted by rakeshtomar82
Hi,

I have a shell script, In which i have variable "var1" and some perl command inside shell script.
Code:
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 hardcoded.
can I write a perl command which will get the vlaue from variable "var1" and add it to the command.txt file.


Thanks
Try
Code:
typeset -x var1='coep -n   rst-a2p-hinje.vci.all.com -c'
perl -pi -e 's/^/$ENV{"var1"} /'  command.txt

This User Gave Thanks to Aia For This Post:
# 3  
Old 09-14-2015
Thanks Aia Smilie

Last edited by vbe; 09-14-2015 at 01:21 PM.. Reason: rm url
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

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 ... (3 Replies)
Discussion started by: jdilts
3 Replies

2. Shell Programming and Scripting

usage of AWK command under perl script

i have two files as shown below t1.txt: argument1 argu2 argu37 t2.txt: 22 33 44 i want o/p as argument1 22 argu2 33 argu37 44 i am trying to merge two file under perl script using following system("paste t1.txt t2.txt | awk... (3 Replies)
Discussion started by: roopa
3 Replies

3. 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

4. Shell Programming and Scripting

Not able to store command inside a shell variable, and run the variable

Hi, I am trying to do the following thing var='date' $var Above command substitutes date for and in turn runs the date command and i am getting the todays date value. I am trying to do the same thing as following, but facing some problems, unique_host_pro="sed -e ' /#/d'... (3 Replies)
Discussion started by: gvinayagam
3 Replies

5. UNIX for Dummies Questions & Answers

Command to display the space usage (memory usage) of a specific directory.

Hi all, Can you please tell me the command, with which one can know the amount of space a specific directory has used. df -k . ---> Displays, the amount of space allocated, and used for a directory. du -k <dir name> - gives me the memory used of all the files inside <dir> But i... (2 Replies)
Discussion started by: abhisheksunkari
2 Replies

6. Shell Programming and Scripting

Confused with the usage of one variable usage

Hi All I am not able to understand the usage of d# in the below variable declaration. FILE_LOC contains the directory path And also help me to know about what will be saved in the variable j. Thanks!!! j=${d#${FILE_LOC}/} (2 Replies)
Discussion started by: mohanm
2 Replies

7. 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

8. Shell Programming and Scripting

Grep command usage in shell

hi, I am facing a problem when i use grep command in shell script. problem is as follows... 1)i has declared an variable (say a) 2)Now i am searching for an pattern in a file and i used the followig command cat /wls_../../scripts/log.txt | grep $a-JUL-08 i am not getting any... (6 Replies)
Discussion started by: hemanth_t
6 Replies

9. Shell Programming and Scripting

Perl Split Command usage

Hi, I am trying to use the split commad to seperate string reading from file. but it dosent give me a correct result. can some body tell me what is the wrong in following scritp. #!/usr/bin/perl -w #use CGI qw(:standard); ... (2 Replies)
Discussion started by: maheshsri
2 Replies

10. Shell Programming and Scripting

Perl: export variable to shell

Hi, I am running a series of scripts and I need to transport a particular variable across many scripts. I thougt of defining an environmental variable which I could access through. But I found that the variable dies as soon as the script ends.. Currently I write this variable to a temporary... (2 Replies)
Discussion started by: oldtrash
2 Replies
Login or Register to Ask a Question