Reputation: 612
I have two regex expressions:
1) egrep \\.$
./lab1.txt - returns a lines ending with a dot
2) egrep '^\w+[aeiou]\b'
./lab1.txt - returns a lines where the first word ends with a vowel
I need to join this expressions. So, I need to return a lines ending with a dot AND where the first word ends with a vowel. How can I do this?
My demo txt file (lab1.txt):
Hello world
Hello world.
London is the capital of GB.
Oslo is the capital of Norway
Oslo is the capital of Norway.
So, the final expression should return:
Hello world.
Oslo is the capital of Norway.
Upvotes: 1
Views: 1116
Reputation: 20889
To answer the original question:
You can use a lookahead-assertion:
^.*?$
) ^.*?\.$
) (?=^\w+[aeiou]\b)^.*?\.$
All together:
(?=^\w+[aeiou]\b)^.*?\.$
(requires multiline mode, if the whole input is a single string, not sure if egrep is working line-wise, but would assume it.)
Upvotes: 0
Reputation: 93636
Don't combine the regexes. Pipe the output from one invocation of egrep
into another invocation of egrep
.
egrep '\.$' ./lab1.txt | egrep '^\w+[aeiou]\b'
Upvotes: 1