?
Solved

grep on hyphen

Posted on 2004-10-06
8
Medium Priority
?
1,046 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 1600 total points
ID: 12245152
In that case, do

for i in `cat list.txt`
do
   grep \\$i *.out >>1.new
done
0
Percona Live Europe 2017 | Sep 25 - 27, 2017

The Percona Live Open Source Database Conference Europe 2017 is the premier event for the diverse and active European open source database community, as well as businesses that develop and use open source database software.

 

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
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.
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

770 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