Solved

grep on hyphen

Posted on 2004-10-06
8
1,025 Views
Last Modified: 2013-12-26
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
Comment
Question by:uluttrell
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
8 Comments
 
LVL 48

Expert Comment

by:Tintin
ID: 12244561
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
 

Author Comment

by:uluttrell
ID: 12245042
Yes, I am wanting to do an exact search.
0
 
LVL 48

Accepted Solution

by:
Tintin earned 400 total points
ID: 12245152
In that case, do

for i in `cat list.txt`
do
   grep \\$i *.out >>1.new
done
0
Independent Software Vendors: 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!

 

Author Comment

by:uluttrell
ID: 12245176
Thanks.  How do you account for this error:
grep: RE error 25: ``\digit'' out of range.
0
 
LVL 48

Expert Comment

by:Tintin
ID: 12245194
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
 

Author Comment

by:uluttrell
ID: 12245217
I'm using Solaris.  Here is the sample data.
--blah==
-_.blah.-_22..blah
-blah.11234.bla
0
 
LVL 48

Expert Comment

by:Tintin
ID: 12245317
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
 

Author Comment

by:uluttrell
ID: 12245351
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

Independent Software Vendors: 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!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question