|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
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
|
|||
|
|||
|
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 |
|
#2
|
|||
|
|||
|
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 |
|
#3
|
|||
|
|||
|
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 |
|
#4
|
|||
|
|||
|
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. |
![]() |
| Viewing: Dev Shed Forums > Operating Systems > UNIX Help > grep is interpolating variable value |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|