grep on hyphen

Greetings Experts,

I have a list that has entries similar to --ldkajflaj--.  I wan't t cat the list and use it in a grep function.  My syntax is:
l=`cat list.txt`
for i in $l
do
grep $i *.out >> 1.new
done

I receieve the following error:  
grep: illegal option -- a
grep: illegal option -- o
grep: illegal option -- m
grep: illegal option -- o
grep: illegal option -- u
Usage: grep -hblcnsviw pattern file . . .

I tried escaping the hyphen also but that yielded the same error.

Thanks in advance for your help.
uluttrellAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
TintinConnect With a Mentor Commented:
In that case, do

for i in `cat list.txt`
do
   grep \\$i *.out >>1.new
done
0
 
TintinCommented:
Are you wanting to do an exact search (ie: including the --)?

If not, you can do

for i in `sed "s/^--//" list.txt`
do
  grep $i *.out >>1.new
done
0
 
uluttrellAuthor Commented:
Yes, I am wanting to do an exact search.
0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
uluttrellAuthor Commented:
Thanks.  How do you account for this error:
grep: RE error 25: ``\digit'' out of range.
0
 
TintinCommented:
What Unix flavour are you using?

Works for me on Redhat and Solaris, although it could be something to do with my sample data.

Could you please post a few lines of real data?
0
 
uluttrellAuthor Commented:
I'm using Solaris.  Here is the sample data.
--blah==
-_.blah.-_22..blah
-blah.11234.bla
0
 
TintinCommented:
What version of Solaris?

I tried your sample data and still don't get any errors?

Are you running the exact same script that I supplied?
0
 
uluttrellAuthor Commented:
I'm running Solaris 8.  I'm running the exact same script that you supplied.  I may have made a typo.  I'm increasing the point value also.  Thanks so much.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.