Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

grep not matching EXACTLY what I tell it to 1

Status
Not open for further replies.

630111

MIS
Oct 30, 2001
127
US
I have a text file...

usdalnpd01 PROD_WINDOWS
usdalphm01 PROD_WINDOWS
usdalqdb01 NON_PROD_WINDOWS
usdalsvc01 NON_PROD_WINDOWS
usdaluat01 NON_PROD_WINDOWS

When I do this...

cat text.file | grep PROD_WINDOWS

I get both the PROD_WINDOWS and NON_PROD_WINDOWS entries.
I also tried

grep 'PROD_WINDOWS' text.file

and the same thing happens. I only want the lines that are PROD_WINDOWS. Is grep not the right tool, or is there some switch I'm missing?

Thanks, in advance!
630111
 
Have you tried this ?
awk '$2=="PROD_WINDOWS"' text.file
Or this ? ([<Space><Tab>])
grep '[ ]PROD_WINDOWS' text.file

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
I'm only really competent in Perl (just) but this is how i'd do it - and it does work on the command line:-

cat text.file | grep "[^\_]PROD_WINDOWS"

returns:-
[red]usdalnpd01 PROD_WINDOWS
usdalphm01 PROD_WINDOWS[/red]

grep is doing what it is told as all the lines contain that string. you need to tell grep NOT - as in this example - to be preceeded by an underscore

:)


Kind Regards
Duncan
 
grep '[^A-Za-z_]PROD_WINDOWS' file

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
PHV - quick as lightning!

630111 - I'd listen to PHV - he DOES know what he/she is talking about!!!


Kind Regards
Duncan
 
my solaris grep knows a 'w' option, and sed always works
/\<abc\>/p


don't forget, RTFMP :) guggach
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top