how to escape dollar in unixcommand


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting how to escape dollar in unixcommand
# 1  
Old 05-14-2010
how to escape dollar in unixcommand

i have

Code:
my @tmp = `egrep 'jpg$|gif$' output.txt`;

perl assumes $ as a variable;
i tried escaping but failed please help me
# 2  
Old 05-14-2010
Try
Code:
my @tmp = `egrep 'jpg\$|gif\$' output.txt`;

Actually, I'd say it has nothing to do with Perl in that case, since egrep is an external command.
It searches for two patterns (incl. "$" regular expression, which stands for "end of line").
I hope I'm not terribly off base Smilie

Last edited by pseudocoder; 05-14-2010 at 02:52 PM..
# 3  
Old 05-14-2010
Two contexts

please anyone can help me in this context

1)use dollar in commands

Code:
my @tmp = `egrep 'jpg$|gif$' output.txt`

2)i want to find a $string variable in my perl program in the above command

Code:
my @tmp = `egrep 'jpg$|gif$|$string' output.txt`

please correct me where ever required please help me with this escaping stuff
# 4  
Old 05-14-2010
Did you try psuedocoder's code?
# 5  
Old 05-14-2010
this is the unfortunate side-effect of cobbling solutions together, but for this Perl has the handy-dandy system() family of commands executing external commands | Perl HowTo.

You'll probably need to handle it differently from what you're doing, or if you're calling this perl from a shell, maybe do a
Code:
for item in $list ;do perl.pl $item ;done

as needed...
# 6  
Old 05-17-2010
If you want to read from a file, do it properly. With Perl, there's almost never a need to call a standard UNIX utility externally, because the functionality is already there.
Code:
open my $file, '<', 'output.txt' or die "Can't open output.txt: $!";
my @tmp = grep { /jpg$/ || /gif$/ } map { chomp } <$file>;
close $file;

Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Ignore dollar value in sed

Hi Guys, I need to replace the string based on specific value by keeping dollar sign input=$1 var=$(echo "@code_temp_table_$value_table"| sed -r "s/\@code/${input}/;s/(nz|sa)_\$value_/\$value1_\1_/" ) Expected if input=nz,sa then nz_temp_table_$value1_table else if any other... (5 Replies)
Discussion started by: Master_Mind
5 Replies

2. Shell Programming and Scripting

Dollar symbol in Shell Script Variable

Hi, I am working on PGP encryption. I am getting public keys from some file. One of the key has dollar sign in it "$" Example: "abc$123" echo 'passphrase='$passphrase --> Giving correct value abc$123 But if I use $passphrase in PGP command getting Invalid passphrase error. If I... (10 Replies)
Discussion started by: Sreehari
10 Replies

3. Shell Programming and Scripting

Grep and dollar command

Hello there, first of all, don't hesitate to notify me if I misbehave. I'm a newbe in the use of this site, and in unix too (in english as well :-) Well, if someone hat a little time to waste, could he explain to me this strange behavior. I'm using ksh under AIX. cdeset=$(su - db2inst1 -c... (8 Replies)
Discussion started by: skitoc
8 Replies

4. Shell Programming and Scripting

Auto escape script to escape special chars in script args

This is a bit off the wall, but I often need to run scripts where there are argument values that contain special characters. For example, $ ./process.exe -t M -N -o temp.mol.s -i ../molfiles/N,N\',N\'\'-trimethylbis\(hexamethylene\)triamine.mol && sfile_space_to_tab.sh temp.mol.s temp.s It... (1 Reply)
Discussion started by: LMHmedchem
1 Replies

5. AIX

Implementing PowerVM without spending a single dollar

Hi experts. I want to setup a training lab. I have a Power 5 standalone server 9110-51A (p5 510) I want to enable PowerVM on it and create two LPARs I don't have money for an HMC I know I can use IVM instead I understand IVM is part of the VIOS software TWO QUESTIONS: 1- If... (12 Replies)
Discussion started by: livehho
12 Replies

6. Shell Programming and Scripting

problem in dollar substitution

Hi, I have a problem in dollar substitution:- $ csv1="first_csv" $ csvnumber=1 $ echo {csv$csvnumber} {csv1} $ echo "${csv$csvnumber}" bad substitution I want first_csv...why is it not working thanks (2 Replies)
Discussion started by: scripter12
2 Replies

7. What is on Your Mind?

65 thousand dollar question

I was just a-wondering through some hardware and software sites, and in one of them, I was scrolling down a UNIX os page when I noticed that the prices for these OS's were climbing alarmingly high; in the 5 to 10 G's. Imagine my surprise when I saw one particular UNIX os selling for 65 freakin'... (10 Replies)
Discussion started by: mud
10 Replies

8. Shell Programming and Scripting

Sum Dollar Amounts

I get a transaction file and I need to sum two of the columns. I each record I get a debit(D) or credit(C) indicator. Then I get an amount field. I need to sum the total dollar value of debits and credits. I know I can loop through each record and get the sum total but is there a better way with... (7 Replies)
Discussion started by: lesstjm
7 Replies

9. UNIX for Dummies Questions & Answers

using $ dollar symbal as text

All, How can I get unix to handle the symbol $ as text rather than thinking its a variable value. e.g When calling a sql script from unix: exec SQL_PACKAGE('OPS$JOHN.EMP') where OPS$JOHN is the owner of the table ($JOHN is not a variable!) Thanks (1 Reply)
Discussion started by: ramit
1 Replies
Login or Register to Ask a Question