UNIX Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsOperating SystemsUNIX Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here
  #1  
Old November 5th, 2004, 10:44 AM
AVS AVS is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2004
Posts: 37 AVS User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 4 m 52 sec
Reputation Power: 4
grep is interpolating variable value

Hi

I have to search in a file all lines containing a variable value at the beginning immeditaley followed by '^'. The value of variable can change dynamically. So if the vraiable $a value is something like "blabla" the following works properly.
But if the variable value contains a dollar symobol or '@' symbol it does not work. How to avoid this. I am trying to do it in k shell script

$a = "$FT68WWWJE@DSF";
grep "^$a\^" inpfile > outfile

If escapingthe $ and @ is the only solution, thenhow can it be done?

Thanks

Reply With Quote
  #2  
Old November 5th, 2004, 11:22 AM
guggach guggach is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jul 2004
Location: Middle Europa
Posts: 1,083 guggach User rank is Corporal (100 - 500 Reputation Level)guggach User rank is Corporal (100 - 500 Reputation Level)guggach User rank is Corporal (100 - 500 Reputation Level)guggach User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 4 Days 19 h 33 m 4 sec
Reputation Power: 9
1) you dont say what tool you are using (i suppose perl)
2) read carefully your regexp
if FTblahblah is empy, you are grepping for '^^' in file
that make less sence

Reply With Quote
  #3  
Old November 5th, 2004, 12:54 PM
AVS AVS is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2004
Posts: 37 AVS User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 4 m 52 sec
Reputation Power: 4
More details - grep problem with special chars

Here are more details:
1) yes, i am using perl tool

2)

#! /opt/perl5/bin/perl
my $a="TCFGHLK";
eval `grep "^$a\^" inpfil.dat > outfil.dat`;

When I check the outfil.dat after executing the above perl prg, it contains all rows which begins with 'TCFGHLK^" as expected

#! /opt/perl5/bin/perl
my $a="$ABC1521";
eval `grep "^$a\^" inpfil.dat > outfil.dat`;

In this case outfil.dat does not contain any rows because unix first interpolates $a and finds $ABC1521 and it will try to interpolate it again. It does not find any variable decalred with "ABC1521" name. So does not get any records.
I want it to search for all rows containing $ABC1521^ in the beginnning. Sometime I might have '@' symbol also in the beginning of string contained in $a.
Any solutions

Dont worry about $a being blank. Only worry is when $a contains '$' or '@' symbols

Any help

Reply With Quote
  #4  
Old November 5th, 2004, 07:53 PM
guggach guggach is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jul 2004
Location: Middle Europa
Posts: 1,083 guggach User rank is Corporal (100 - 500 Reputation Level)guggach User rank is Corporal (100 - 500 Reputation Level)guggach User rank is Corporal (100 - 500 Reputation Level)guggach User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 4 Days 19 h 33 m 4 sec
Reputation Power: 9
you are stting $a to $ABC1521
perl interpretes it to a variablename $ABC1521
if you want $ABC1521 mask the $ sign.

it make for me not really sence to use grep in perl.

Reply With Quote
Reply

Viewing: Dev Shed ForumsOperating SystemsUNIX Help > grep is interpolating variable value


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway