I am trying to create an egrep command to grep the number of lines containing a specific text from a text-file but seem to have an error somewhere.
The text-file contains several thousand lines and has the expression
Lastname in several lines. Problem is, there are also expressions like
abcLastname in there which I DON'T want to grab.
So the definition of the RegExpression should look like this:
EITHER there is no text at all in the line before
OR there is text in the line BUT a space has to be between the random text and
I tried with
((.+\ )?|(^.))Lastname and
((.+\ )?|[^.])Lastname but it always results in the egrep command finding expressions like
Where is my mistake? The first part
(.+\ ) ("If there is text, there HAS to be a space afterwards") seems to work fine but the second part ("OR there is no text at all") does not seem to work.
Isn't there a special character that I can use to simply check if whatever comes after it is the FIRST expression/character in the line? I cannot find that information online unfortunately.
Thanks to all of you in advance for your help