Operating System - HP-UX
1834140 Members
3103 Online
110064 Solutions
New Discussion

Stop regular expression expanding list of files

 
SOLVED
Go to solution
Ian Dennison_1
Honored Contributor

Stop regular expression expanding list of files

I have a program that stores a value containing an asterisk (a regular expression), which I need to grep against in a file. However, the program keeps expanding the regular expression to list all the files!

eg export TEMPLATE='ora*log'
export SRHTEMPLATE=`echo $TEMPLATE |sed 's/\*/\\\*/g'`
grep -v $SRHTEMPLATE /tmp/file >/tmp/file2

The problem is that SRHTEMPLATE is expanded to a list of all files matching "ora*log". But! Just using $TEMPLATE for the grep command does not suppress the required lines.

Share and Enjoy! Ian Dennison


Building a dumber user
4 REPLIES 4
TwoProc
Honored Contributor
Solution

Re: Stop regular expression expanding list of files

`echo "$TEMPLATE" |sed 's/\*/\\\*/g'`

should work...
We are the people our parents warned us about --Jimmy Buffett
RAC_1
Honored Contributor

Re: Stop regular expression expanding list of files

SRHTEMPLATE=`echo $TEMPLATE |sed 's/\*/\\\*/g'`

Change this to
SRHTEMPLATE=`echo "$TEMPLATE |sed 's/\*/\\\*/g'"`
There is no substitute to HARDWORK
Ian Dennison_1
Honored Contributor

Re: Stop regular expression expanding list of files

John,

bc02n0v0> echo "$PREVTMPL" |sed 's/\*/\\\*/g'
ora\*log
bc02n0v0> `echo "$PREVTMPL" |sed 's/\*/\\\*/g'`
sh: ora\*log: not found.
bc02n0v0>

Sorry, doesn't work inside back quotes (works without backquotes).

Share and Enjoy! Ian
Building a dumber user
Ian Dennison_1
Honored Contributor

Re: Stop regular expression expanding list of files

RAC,

Double quotes around most of it?

bc02n0v0> `echo "$PREVTMPL |sed 's/\*/\\\*/g'"`
sh: ora*log: not found.

Strange, after a little experimentation what follows,...

Pt 1 - by itself on the command line, inside back-quotes
bc02n0v0> `echo "$PREVTMPL" |sed 's/\*/\\\*/g'`
sh: ora\*log: not found.

Pt 2 - in variable assignment, inside back quotes
bc02n0v0> export SRHTMPL=`echo "$PREVTMPL" |sed 's/\*/\\\*/g'`
bc02n0v0> echo $SRHTMPL
ora\*log
bc02n0v0>

So the same code has different results depending if it is an RValue or not.

Thanks for the assistance - as you were both right, you both get 10 pts.

Share and Enjoy! Ian
Building a dumber user