1833439 Members
3578 Online
110052 Solutions
New Discussion

grep -E using variables

 
SOLVED
Go to solution
Manuales
Super Advisor

grep -E using variables

HOw can i fix the following?

$ cat > arch_prueba
dani
paula
pedro
beto
$ grep -E '$a | $b' arch_prueba
grep: $ anchor not at end of pattern.
$ grep -E '"$a|$b' arch_prueba
grep: $ anchor not at end of pattern.
$ grep -E '`echo $a`|`echo $b`' arch_prueba
grep: $ anchor not at end of pattern.

please let me know.
5 REPLIES 5
Manuales
Super Advisor

Re: grep -E using variables

i forgot tell i did the followinig:

$ a=dani
$ b=beto

$ cat > arch_prueba
dani
paula
pedro
beto
$ grep -E '$a | $b' arch_prueba
grep: $ anchor not at end of pattern.
$ grep -E '"$a|$b' arch_prueba
grep: $ anchor not at end of pattern.
$ grep -E '`echo $a`|`echo $b`' arch_prueba
grep: $ anchor not at end of pattern.


how can i fix it?
Manuales
Super Advisor

Re: grep -E using variables

Really i watn to do:

a=`date "+%b %d"`
aa=`perl -MPOSIX -le 'print strftime "%b %d",localtime(time-86400)'`

$ grep -E '$a|$aa' /var/adm/syslog/syslog.log
grep: $ anchor not at end of pattern.

please help me !!!
thanks in advance.
James R. Ferguson
Acclaimed Contributor
Solution

Re: grep -E using variables

Hi Manuales:

# a=paula; b=beto
# grep -e $a -e $b arcj_prueba
paula
beto

Regards!

...JRF...
Manuales
Super Advisor

Re: grep -E using variables

thanks a lot
it worked :

grep -e "$a" -e "$aa" /var/adm/lp/log

James R. Ferguson
Acclaimed Contributor

Re: grep -E using variables

Hi (again) Manuales:

Although I prefer the '-e' with the separate operands, had you used double quotes, you could have used '-E' :

# a=paula; b=beto
# grep -E "$a|$b" arch_prueba
paula
beto

Regards!

...JRF...