Solved

grep on hyphen

Posted on 2004-10-06
8
1,003 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
  • 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
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 

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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Windows Drag & Drop Location 2 100
centeredAverage challenge 8 163
either24  challenge 19 97
twoTwo  challenge 35 101
Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
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.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

776 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