I am using egrep to look through scripts in our perforce NAS.
i am trying to find where we use RCP & RSH....The problem i have is that 1) I suck at REGEX; 2) i am picking up junk I am not interested in. For example if a file has the word strcpy..it picks up on RCP..or ownership..hits on RSH.
Obviously i am not interested in those, but I don't want to exclude lines based on the words ownership or strcpy...because they may be used in conjunction...and its not a complete list.
Here is my regex
'ftp|rcp|rsh'
How can mod these to hit on FTP, but not SFTP...rcp but no strcpy, rsh but not ownership.....etc.?
So Things I would want to match.
ftp
`ftp`
/ftp/
"PUNCT"FTP"PUNCT"
Checking for the whole words in a file : By default, grep matches the given string/pattern even if it is found as a substring in a file. The -w option to grep makes it match only the whole words.
The easiest of the two commands is to use grep's -w option. This will find only lines that contain your target word as a complete word. Run the command "grep -w hub" against your target file and you will only see lines that contain the word "hub" as a complete word.
Matches using extended regular expressions. –e pattern. Specifies one or more patterns separated by newlines for which grep is to search. You can indicate each pattern with a separate –e option character, or with newlines within pattern.
Maybe you need something like this:
\b
< - this is the border of word
\bpattern\b
<- this pattern will match only pattern
, but not otherbigpatternthatyounotneed
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With