understand -w option with grep
I had wanted to include some abbreviations in my searches. cu, al and maybe a few more. I have not been able to get them to match only whole words ie "cu" and "al" They seem to match "cut" "all" "alabama' "cucumber" etc..
Is it correct that the -w option with grep would cause the pattern "cu" to not return a match on "cut".
To use the -w option with grep do I just include it along with any other options at the beginning?
I did not see in man where '-woic -f patternfile file' should conflict with one another.
How far off base am I this time?
I can include code or more context if needed. My script is getting big. I would only post what I hope is the appropriate section if that would do.
Thanks very much,
I had a few minutes to mess with this at a command line
If I put the word I expect to return "garden" then follow it by the other words that should not be in the file "al" "cu"
But if I reverse the order of the patterns
If I seach without the word I was expexting to return
tster is a html file about gardening, I just changed the long name it had to tster.
I get very similar results with a plain text file.
I fear it may be time for me to understand regular expressions. Hopefully not yet, just figuring how to use
these plain commands would be great for now if possible.
I don't think there should be any issue combining those options.
grep -e cu -e al filename (the quotes are not needed)
egrep 'cu|al' filename
I think I created a small html file with kompoze, to have better control over testing this out.
It only has seven words in it:
linux computer network
cucumber dual almost cups
I got the same behaviour as in the above post when I changed to egrep 'pattern|pattern|pattern' etc...
Anything else anyone thinks for me to look into is great
The essential purpose of "-w" is to say that, in order to "match," the specified pattern must be both preceded and followed by a non-word character (or the beginning/end of line).
I don't use "-w" in any situation more complicated than that.
Yes that is I believe all I want out of it
here is output of that seven word file with -ow options
here it is with only the -w option
The color is missing but in the second output the searched terms are highlighted. Maybe the html stuff is is interfering?
I a going to go double check with plain text file
Yes same behaviour with a text file,
What could I have screwed up to be causing this? Some kind of envirioment
Thanks again to all,
I reinstalled only my / and still had the problem, tried a while longer to figure out the prob, gave up and then reinstalled /home and now the problem is gone.
I suspect that during my experimenting with grep,sed,awk etc... I accidently screwed up a config file that bash looks at. Just a guess. Don't put much stock in it. I have yet to be correct about anything System or Programming related.
|All times are GMT -5. The time now is 07:56 PM.|