Help from any UNIX guru please. ( Update - problem solved )

gittyup

Diamond Member
Nov 7, 2000
5,036
0
0
Here is the problem.

I am doing a grep on a file. I only want lines where the search string is matched exactly.

command % grep exam filename

filename contents:
line 1)here:is:my:exam:contents
line 2)here:is:yourroblem:example

The problem is that grep will return both lines because it matches all or part of the search string. Lines that conatina both "exam" and "example" are returned. I only want line 1 to be returned, an exact match. I have looked thru the man pages and I don't see any options that will work. I know it can be done. I am also looking into awk. Any ideas????
 

aimn

Banned
Feb 14, 2001
683
0
0
I dont know the answer but I know who does! Go to HP Forums and post this question. You will have an answer within minutes.


Actually I posted the question for you, so you wouldnt have to go through signing up and everything. Sounds like you might want to do that anyways. So to speed things up, I posted it quick. I will post there answer here.
 

aimn

Banned
Feb 14, 2001
683
0
0
If the word you are looking for is surrounded by a space, or any other character ; etc..) then you can do a: grep " exam " filename
 

KarlHungus

Senior member
Nov 16, 1999
638
0
0
If I get the problem correctly then sysadmin's suggestion should work.

grep "exam:" filename
 

gittyup

Diamond Member
Nov 7, 2000
5,036
0
0
Normally it would, but in this case, you never know what is going to be on either side of exam.

It may be :exam:
or :,exam:
or :exam,:
or :exam,,,:
or :;;exam,:

It varies quite a bit in format. That's why I need to just search for exam exactly how it is.
 

KarlHungus

Senior member
Nov 16, 1999
638
0
0
Try using egrep instead, and do the following

egrep "exam: |exam," filename

It should work for the examples you just gave.

Edit - uh oh, pipes made that string mad. There should not be a space after : in that expression.
 

aimn

Banned
Feb 14, 2001
683
0
0
There is an option to grep that will give you only the exact match of the string you enter.

Check the man page for grep.
The -x option returns only exact matches.
 

gittyup

Diamond Member
Nov 7, 2000
5,036
0
0
sysadmin

Yes, there is an option -x for fgrep. Although, I think the -x option will return if the pattern matches the entire line.

At any rate, I went ahead and coded a "C" solution to the problem. Thanks for all your suggestions people.
 

MereMortal

Golden Member
Oct 16, 2000
1,919
2
81
Did you try this?
% grep -w exam filename

Edit: This flag works, but unfortunately it is not standard. It seems to be on Sun OS's but not on IRIX.
 
sale-70-410-exam    | Exam-200-125-pdf    | we-sale-70-410-exam    | hot-sale-70-410-exam    | Latest-exam-700-603-Dumps    | Dumps-98-363-exams-date    | Certs-200-125-date    | Dumps-300-075-exams-date    | hot-sale-book-C8010-726-book    | Hot-Sale-200-310-Exam    | Exam-Description-200-310-dumps?    | hot-sale-book-200-125-book    | Latest-Updated-300-209-Exam    | Dumps-210-260-exams-date    | Download-200-125-Exam-PDF    | Exam-Description-300-101-dumps    | Certs-300-101-date    | Hot-Sale-300-075-Exam    | Latest-exam-200-125-Dumps    | Exam-Description-200-125-dumps    | Latest-Updated-300-075-Exam    | hot-sale-book-210-260-book    | Dumps-200-901-exams-date    | Certs-200-901-date    | Latest-exam-1Z0-062-Dumps    | Hot-Sale-1Z0-062-Exam    | Certs-CSSLP-date    | 100%-Pass-70-383-Exams    | Latest-JN0-360-real-exam-questions    | 100%-Pass-4A0-100-Real-Exam-Questions    | Dumps-300-135-exams-date    | Passed-200-105-Tech-Exams    | Latest-Updated-200-310-Exam    | Download-300-070-Exam-PDF    | Hot-Sale-JN0-360-Exam    | 100%-Pass-JN0-360-Exams    | 100%-Pass-JN0-360-Real-Exam-Questions    | Dumps-JN0-360-exams-date    | Exam-Description-1Z0-876-dumps    | Latest-exam-1Z0-876-Dumps    | Dumps-HPE0-Y53-exams-date    | 2017-Latest-HPE0-Y53-Exam    | 100%-Pass-HPE0-Y53-Real-Exam-Questions    | Pass-4A0-100-Exam    | Latest-4A0-100-Questions    | Dumps-98-365-exams-date    | 2017-Latest-98-365-Exam    | 100%-Pass-VCS-254-Exams    | 2017-Latest-VCS-273-Exam    | Dumps-200-355-exams-date    | 2017-Latest-300-320-Exam    | Pass-300-101-Exam    | 100%-Pass-300-115-Exams    |
http://www.portvapes.co.uk/    | http://www.portvapes.co.uk/    |