Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1078
  • Last Modified:

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.
0
uluttrell
Asked:
uluttrell
  • 4
  • 4
1 Solution
 
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
 
TintinCommented:
In that case, do

for i in `cat list.txt`
do
   grep \\$i *.out >>1.new
done
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 4
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now